-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(app-lite): add cloudflare pages support
- Loading branch information
1 parent
3168ba7
commit a78056b
Showing
8 changed files
with
1,760 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
module.exports = { | ||
extends: ['custom-next'], | ||
extends: ['custom-next', 'plugin:eslint-plugin-next-on-pages/recommended'], | ||
plugins: ['eslint-plugin-next-on-pages'], | ||
root: true, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
import { setupDevPlatform } from '@cloudflare/next-on-pages/next-dev'; | ||
import { configureRuntimeEnv } from 'next-runtime-env/build/configure.js'; | ||
|
||
configureRuntimeEnv(); | ||
|
||
/** @type {import('next').NextConfig} */ | ||
const nextConfig = { | ||
output: 'standalone', | ||
poweredByHeader: false, | ||
reactStrictMode: true, | ||
}; | ||
const nextConfig = {}; | ||
|
||
if (process.env.NODE_ENV === 'development') { | ||
await setupDevPlatform(); | ||
} | ||
|
||
export default nextConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,38 @@ | ||
import { GetServerSideProps } from 'next'; | ||
import { useRouter } from 'next/router'; | ||
import { useEffect, useMemo } from 'react'; | ||
|
||
import { RPC } from 'nb-near'; | ||
|
||
import { getReceipt } from '@/libs/rpc'; | ||
import { useNetworkStore } from '@/stores/network'; | ||
|
||
const network = useNetworkStore.getState().network; | ||
|
||
const rpc = | ||
network === 'mainnet' | ||
? new RPC('https://beta.rpc.mainnet.near.org') | ||
: new RPC('https://beta.rpc.testnet.near.org'); | ||
|
||
export const getServerSideProps = (async (context) => { | ||
const { | ||
query: { hash }, | ||
} = context; | ||
|
||
if (typeof hash === 'string') { | ||
const receipt = await getReceipt(rpc, hash); | ||
|
||
if (receipt?.result) { | ||
return { | ||
redirect: { | ||
destination: `/txns/${receipt.result.parent_transaction_hash}`, | ||
permanent: false, | ||
}, | ||
}; | ||
} | ||
} | ||
|
||
return { | ||
notFound: true, | ||
}; | ||
}) satisfies GetServerSideProps; | ||
|
||
const Hash = () => null; | ||
const Hash = () => { | ||
const router = useRouter(); | ||
const { hash } = router.query; | ||
const network = useNetworkStore.getState().network; | ||
|
||
const rpc = useMemo(() => { | ||
return network === 'mainnet' | ||
? new RPC('https://beta.rpc.mainnet.near.org') | ||
: new RPC('https://beta.rpc.testnet.near.org'); | ||
}, [network]); | ||
|
||
useEffect(() => { | ||
const fetchAndRedirect = async () => { | ||
if (typeof hash === 'string') { | ||
const receipt = await getReceipt(rpc, hash); | ||
if (receipt?.result) { | ||
router.push(`/txns/${receipt.result.parent_transaction_hash}`); | ||
} else { | ||
router.push('/'); // TODO add 404 page | ||
} | ||
} | ||
}; | ||
|
||
fetchAndRedirect(); | ||
}, [hash, rpc, router]); | ||
|
||
return null; | ||
}; | ||
|
||
export default Hash; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
name = "app-lite" | ||
compatibility_date = "2024-07-29" | ||
compatibility_flags = ["nodejs_compat"] | ||
pages_build_output_dir = ".vercel/output/static" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.