Skip to content

Commit

Permalink
feat(app-lite): add cloudflare pages support
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewklau committed Nov 9, 2024
1 parent 3168ba7 commit a78056b
Show file tree
Hide file tree
Showing 8 changed files with 1,760 additions and 122 deletions.
25 changes: 7 additions & 18 deletions .github/workflows/build-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ jobs:
[
api,
app,
app-lite,
backend,
indexer-balance,
indexer-base,
Expand Down Expand Up @@ -95,7 +94,7 @@ jobs:
run: |
kubectl config set-context --current --namespace=nearblocks-testnet
# Define the list of services for testnet deployment (without app-lite)
# Define the list of services for testnet deployment
services=(api app backend indexer-balance indexer-base indexer-events explorer-selector aggregates)
failed_deployments=()
Expand Down Expand Up @@ -148,8 +147,8 @@ jobs:
run: |
kubectl config set-context --current --namespace=nearblocks
# Define the list of services for mainnet deployment (includes app-lite)
services=(api app app-lite backend indexer-balance indexer-base indexer-events indexer-dex indexer-multichain explorer-selector aggregates)
# Define the list of services for mainnet deployment
services=(api app backend indexer-balance indexer-base indexer-events indexer-dex indexer-multichain explorer-selector aggregates)
failed_deployments=()
for service in "${services[@]}"; do
Expand All @@ -158,12 +157,7 @@ jobs:
# Ensure service_sha is valid before updating deployment
if [[ -n "$service" && -n "$service_sha" && "$service_sha" != "false" && "$service_sha" != "null" ]]; then
# Adjust the deployment name for app-lite specifically
if [[ "$service" == "app-lite" ]]; then
deployment_name="mainnet-lite-lite"
else
deployment_name="mainnet-$service"
fi
deployment_name="mainnet-$service"
image_name="ghcr.io/nearblocks/$service:$service_sha"
echo "Updating deployment for $deployment_name with image: $image_name"
Expand Down Expand Up @@ -191,18 +185,13 @@ jobs:
run: |
kubectl config set-context --current --namespace=nearblocks
# Services to rollback for mainnet (includes app-lite with specific name)
services=(api app app-lite backend indexer-balance indexer-base indexer-events indexer-dex indexer-multichain explorer-selector aggregates)
# Services to rollback for mainnet
services=(api app backend indexer-balance indexer-base indexer-events indexer-dex indexer-multichain explorer-selector aggregates)
for service in "${services[@]}"; do
service_sha=$(echo '${{ needs.build.outputs.matrix-result }}' | jq -r ".[\"$service\"]")
# Adjust rollback deployment name for app-lite specifically
if [[ "$service" == "app-lite" ]]; then
deployment_name="mainnet-lite-lite"
else
deployment_name="mainnet-$service"
fi
deployment_name="mainnet-$service"
if [[ "$service_sha" != "false" && "$service_sha" != "null" ]]; then
echo "Attempting rollback for $deployment_name"
Expand Down
3 changes: 2 additions & 1 deletion apps/app-lite/.eslintrc.cjs
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,
};
11 changes: 6 additions & 5 deletions apps/app-lite/next.config.mjs
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;
10 changes: 8 additions & 2 deletions apps/app-lite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
"build": "next build",
"start": "next start",
"lint": "tsc --noEmit && eslint ./ --fix",
"lint:check": "tsc --noEmit && eslint ./"
"lint:check": "tsc --noEmit && eslint ./",
"pages:build": "npx @cloudflare/next-on-pages",
"preview": "yarn run pages:build && wrangler pages dev",
"deploy": "yarn run pages:build && wrangler pages deploy"
},
"dependencies": {
"ahooks": "3.7.11",
Expand All @@ -23,18 +26,21 @@
"zustand": "4.5.2"
},
"devDependencies": {
"@cloudflare/next-on-pages": "^1.13.5",
"@types/big.js": "~6.2",
"@types/node": "~20.8",
"@types/react": "~18.2",
"@types/react-dom": "~18.2",
"autoprefixer": "~10.4",
"eslint-config-custom-next": "*",
"eslint-plugin-next-on-pages": "^1.13.5",
"nb-near": "*",
"nb-tsconfig": "*",
"nb-types": "*",
"postcss": "~8.4",
"tailwindcss": "~3.4",
"typescript": "~5.2"
"typescript": "~5.2",
"vercel": "^37.14.0"
},
"resolutions": {
"react-singleton-hook": "4.0.1"
Expand Down
62 changes: 30 additions & 32 deletions apps/app-lite/src/pages/hash/[hash].tsx
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;
4 changes: 4 additions & 0 deletions apps/app-lite/wrangler.toml
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"
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"prettier": "3.0.3",
"prettier-plugin-embed": "0.3.2",
"prettier-plugin-sql": "0.18.0",
"turbo": "^1.13.3"
"turbo": "^1.13.3",
"wrangler": "^3.86.0"
},
"packageManager": "yarn@1.22.19",
"engines": {
Expand Down
Loading

0 comments on commit a78056b

Please sign in to comment.