From b7ae3f29d953636a7dc3de595a2faaa424f11e0a Mon Sep 17 00:00:00 2001 From: Huang Xin Date: Mon, 10 Feb 2025 16:58:30 +0100 Subject: [PATCH] chore: support deployment with open-next on cloudflare (#347) --- apps/readest-app/.env.local.example | 7 ++ apps/readest-app/.gitignore | 4 + apps/readest-app/open-next.config.ts | 29 +++++ apps/readest-app/package.json | 5 +- apps/readest-app/wrangler.json | 12 +++ pnpm-lock.yaml | 151 ++++++++++++++++++++++----- 6 files changed, 179 insertions(+), 29 deletions(-) create mode 100644 apps/readest-app/open-next.config.ts create mode 100644 apps/readest-app/wrangler.json diff --git a/apps/readest-app/.env.local.example b/apps/readest-app/.env.local.example index d5a1f5c7..3ada9deb 100644 --- a/apps/readest-app/.env.local.example +++ b/apps/readest-app/.env.local.example @@ -6,3 +6,10 @@ NEXT_PUBLIC_SUPABASE_ANON_KEY=YOUR_SUPABASE_ANON_KEY DEEPL_PRO_API_KEY=YOUR_DEEPL_PRO_API_KEY DEEPL_FREE_API_KEY=YOUR_DEEPL_FREE_API_KEY + +R2_TOKEN_VALUE=YOUR_R2_TOKEN_VALUE +R2_ACCESS_KEY_ID=YOUR_R2_ACCESS_KEY_ID +R2_SECRET_ACCESS_KEY=YOUR_R2_SECRET_ACCESS_KEY +R2_BUCKET_NAME=YOUR_R2_BUCKET_NAME +R2_ACCOUNT_ID=YOUR_R2_ACCOUNT_ID +R2_REGION=YOUR_R2_REGION diff --git a/apps/readest-app/.gitignore b/apps/readest-app/.gitignore index d551b6a1..7c508dda 100644 --- a/apps/readest-app/.gitignore +++ b/apps/readest-app/.gitignore @@ -40,6 +40,10 @@ tauri.*.conf.json # vercel .vercel +# open-next +.open-next +.wrangler + # typescript *.tsbuildinfo next-env.d.ts diff --git a/apps/readest-app/open-next.config.ts b/apps/readest-app/open-next.config.ts new file mode 100644 index 00000000..b219a91b --- /dev/null +++ b/apps/readest-app/open-next.config.ts @@ -0,0 +1,29 @@ +// @ts-nocheck +// default open-next.config.ts file created by @opennextjs/cloudflare + +import type { OpenNextConfig } from '@opennextjs/aws/types/open-next.js'; +import cache from '@opennextjs/cloudflare/kv-cache'; + +const config: OpenNextConfig = { + default: { + override: { + wrapper: 'cloudflare-node', + converter: 'edge', + // set `incrementalCache` to "dummy" to disable KV cache + incrementalCache: async () => cache, + tagCache: 'dummy', + queue: 'dummy', + }, + }, + + middleware: { + external: true, + override: { + wrapper: 'cloudflare-edge', + converter: 'edge', + proxyExternalRequest: 'fetch', + }, + }, +}; + +export default config; diff --git a/apps/readest-app/package.json b/apps/readest-app/package.json index 4e08b71a..486664bc 100644 --- a/apps/readest-app/package.json +++ b/apps/readest-app/package.json @@ -26,7 +26,10 @@ "build-macos-universial": "dotenv -e .env.tauri.local -e .env.apple-nonstore.local -- tauri build -t universal-apple-darwin --bundles dmg", "build-macos-universial-appstore": "dotenv -e .env.tauri.local -e .env.apple-appstore.local -- tauri build -t universal-apple-darwin --bundles app --config src-tauri/tauri.appstore.conf.json", "build-macos-universial-appstore-dev": "dotenv -e .env.tauri.local -e .env.apple-appstore-dev.local -- tauri build -t universal-apple-darwin --bundles app --config src-tauri/tauri.appstore-dev.conf.json", - "release-macos-universial-appstore": "dotenv -e .env.tauri.local -e .env.apple-appstore.local -- bash scripts/release-mac-appstore.sh" + "release-macos-universial-appstore": "dotenv -e .env.tauri.local -e .env.apple-appstore.local -- bash scripts/release-mac-appstore.sh", + "preview": "NEXT_PUBLIC_APP_PLATFORM=web opennextjs-cloudflare && wrangler dev", + "deploy": "NEXT_PUBLIC_APP_PLATFORM=web opennextjs-cloudflare && wrangler deploy", + "cf-typegen": "wrangler types --env-interface CloudflareEnv cloudflare-env.d.ts" }, "dependencies": { "@aws-sdk/client-s3": "^3.735.0", diff --git a/apps/readest-app/wrangler.json b/apps/readest-app/wrangler.json new file mode 100644 index 00000000..4759c3f6 --- /dev/null +++ b/apps/readest-app/wrangler.json @@ -0,0 +1,12 @@ +{ + "$schema": "node_modules/wrangler/config-schema.json", + "main": ".open-next/worker.js", + "name": "readest-web", + "compatibility_date": "2025-02-04", + "compatibility_flags": ["nodejs_compat"], + "assets": { + "directory": ".open-next/assets", + "binding": "ASSETS" + }, + "kv_namespaces": [] +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3d9fba04..1dc396e4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1387,6 +1387,10 @@ packages: resolution: {integrity: sha512-hhUZlBWYuh9t6ycAcN90XOyG76C1AzwxZZgaCVPMYpWqqk9uMFo7HGG5Zu2cEhCJn7DdOi5krBmlibWWWPgdsw==} engines: {node: '>=18.0.0'} + '@smithy/core@3.1.2': + resolution: {integrity: sha512-htwQXkbdF13uwwDevz9BEzL5ABK+1sJpVQXywwGSH973AVOvisHNfpcB8A8761G6XgHoS2kHPqc9DqHJ2gp+/Q==} + engines: {node: '>=18.0.0'} + '@smithy/credential-provider-imds@4.0.1': resolution: {integrity: sha512-l/qdInaDq1Zpznpmev/+52QomsJNZ3JkTl5yrTl02V6NBgJOQ4LY0SFw/8zsMwj3tLe8vqiIuwF6nxaEwgf6mg==} engines: {node: '>=18.0.0'} @@ -1451,14 +1455,26 @@ packages: resolution: {integrity: sha512-Z9m67CXizGpj8CF/AW/7uHqYNh1VXXOn9Ap54fenWsCa0HnT4cJuE61zqG3cBkTZJDCy0wHJphilI41co/PE5g==} engines: {node: '>=18.0.0'} + '@smithy/middleware-endpoint@4.0.3': + resolution: {integrity: sha512-YdbmWhQF5kIxZjWqPIgboVfi8i5XgiYMM7GGKFMTvBei4XjNQfNv8sukT50ITvgnWKKKpOtp0C0h7qixLgb77Q==} + engines: {node: '>=18.0.0'} + '@smithy/middleware-retry@4.0.3': resolution: {integrity: sha512-TiKwwQTwUDeDtwWW8UWURTqu7s6F3wN2pmziLU215u7bqpVT9Mk2oEvURjpRLA+5XeQhM68R5BpAGzVtomsqgA==} engines: {node: '>=18.0.0'} + '@smithy/middleware-retry@4.0.4': + resolution: {integrity: sha512-wmxyUBGHaYUqul0wZiset4M39SMtDBOtUr2KpDuftKNN74Do9Y36Go6Eqzj9tL0mIPpr31ulB5UUtxcsCeGXsQ==} + engines: {node: '>=18.0.0'} + '@smithy/middleware-serde@4.0.1': resolution: {integrity: sha512-Fh0E2SOF+S+P1+CsgKyiBInAt3o2b6Qk7YOp2W0Qx2XnfTdfMuSDKUEcnrtpxCzgKJnqXeLUZYqtThaP0VGqtA==} engines: {node: '>=18.0.0'} + '@smithy/middleware-serde@4.0.2': + resolution: {integrity: sha512-Sdr5lOagCn5tt+zKsaW+U2/iwr6bI9p08wOkCp6/eL6iMbgdtc2R5Ety66rf87PeohR0ExI84Txz9GYv5ou3iQ==} + engines: {node: '>=18.0.0'} + '@smithy/middleware-stack@4.0.1': resolution: {integrity: sha512-dHwDmrtR/ln8UTHpaIavRSzeIk5+YZTBtLnKwDW3G2t6nAupCiQUvNzNoHBpik63fwUaJPtlnMzXbQrNFWssIA==} engines: {node: '>=18.0.0'} @@ -1503,6 +1519,10 @@ packages: resolution: {integrity: sha512-0yApeHWBqocelHGK22UivZyShNxFbDNrgREBllGh5Ws0D0rg/yId/CJfeoKKpjbfY2ju8j6WgDUGZHYQmINZ5w==} engines: {node: '>=18.0.0'} + '@smithy/smithy-client@4.1.3': + resolution: {integrity: sha512-A2Hz85pu8BJJaYFdX8yb1yocqigyqBzn+OVaVgm+Kwi/DkN8vhN2kbDVEfADo6jXf5hPKquMLGA3UINA64UZ7A==} + engines: {node: '>=18.0.0'} + '@smithy/types@4.1.0': resolution: {integrity: sha512-enhjdwp4D7CXmwLtD6zbcDMbo6/T6WtuuKCY49Xxc6OMOmUWlBEBDREsxxgV2LIdeQPW756+f97GzcgAwp3iLw==} engines: {node: '>=18.0.0'} @@ -1539,10 +1559,18 @@ packages: resolution: {integrity: sha512-7c5SF1fVK0EOs+2EOf72/qF199zwJflU1d02AevwKbAUPUZyE9RUZiyJxeUmhVxfKDWdUKaaVojNiaDQgnHL9g==} engines: {node: '>=18.0.0'} + '@smithy/util-defaults-mode-browser@4.0.4': + resolution: {integrity: sha512-Ej1bV5sbrIfH++KnWxjjzFNq9nyP3RIUq2c9Iqq7SmMO/idUR24sqvKH2LUQFTSPy/K7G4sB2m8n7YYlEAfZaw==} + engines: {node: '>=18.0.0'} + '@smithy/util-defaults-mode-node@4.0.3': resolution: {integrity: sha512-CVnD42qYD3JKgDlImZ9+On+MqJHzq9uJgPbMdeBE8c2x8VJ2kf2R3XO/yVFx+30ts5lD/GlL0eFIShY3x9ROgQ==} engines: {node: '>=18.0.0'} + '@smithy/util-defaults-mode-node@4.0.4': + resolution: {integrity: sha512-HE1I7gxa6yP7ZgXPCFfZSDmVmMtY7SHqzFF55gM/GPegzZKaQWZZ+nYn9C2Cc3JltCMyWe63VPR3tSFDEvuGjw==} + engines: {node: '>=18.0.0'} + '@smithy/util-endpoints@3.0.1': resolution: {integrity: sha512-zVdUENQpdtn9jbpD9SCFK4+aSiavRb9BxEtw9ZGUR1TYo6bBHbIoi7VkrFQ0/RwZlzx0wRBaRmPclj8iAoJCLA==} engines: {node: '>=18.0.0'} @@ -4708,26 +4736,26 @@ snapshots: '@aws-sdk/util-user-agent-browser': 3.734.0 '@aws-sdk/util-user-agent-node': 3.734.0 '@smithy/config-resolver': 4.0.1 - '@smithy/core': 3.1.1 + '@smithy/core': 3.1.2 '@smithy/fetch-http-handler': 5.0.1 '@smithy/hash-node': 4.0.1 '@smithy/invalid-dependency': 4.0.1 '@smithy/middleware-content-length': 4.0.1 - '@smithy/middleware-endpoint': 4.0.2 - '@smithy/middleware-retry': 4.0.3 - '@smithy/middleware-serde': 4.0.1 + '@smithy/middleware-endpoint': 4.0.3 + '@smithy/middleware-retry': 4.0.4 + '@smithy/middleware-serde': 4.0.2 '@smithy/middleware-stack': 4.0.1 '@smithy/node-config-provider': 4.0.1 '@smithy/node-http-handler': 4.0.2 '@smithy/protocol-http': 5.0.1 - '@smithy/smithy-client': 4.1.2 + '@smithy/smithy-client': 4.1.3 '@smithy/types': 4.1.0 '@smithy/url-parser': 4.0.1 '@smithy/util-base64': 4.0.0 '@smithy/util-body-length-browser': 4.0.0 '@smithy/util-body-length-node': 4.0.0 - '@smithy/util-defaults-mode-browser': 4.0.3 - '@smithy/util-defaults-mode-node': 4.0.3 + '@smithy/util-defaults-mode-browser': 4.0.4 + '@smithy/util-defaults-mode-node': 4.0.4 '@smithy/util-endpoints': 3.0.1 '@smithy/util-middleware': 4.0.1 '@smithy/util-retry': 4.0.1 @@ -4739,12 +4767,12 @@ snapshots: '@aws-sdk/core@3.734.0': dependencies: '@aws-sdk/types': 3.734.0 - '@smithy/core': 3.1.1 + '@smithy/core': 3.1.2 '@smithy/node-config-provider': 4.0.1 '@smithy/property-provider': 4.0.1 '@smithy/protocol-http': 5.0.1 '@smithy/signature-v4': 5.0.1 - '@smithy/smithy-client': 4.1.2 + '@smithy/smithy-client': 4.1.3 '@smithy/types': 4.1.0 '@smithy/util-middleware': 4.0.1 fast-xml-parser: 4.4.1 @@ -4766,7 +4794,7 @@ snapshots: '@smithy/node-http-handler': 4.0.2 '@smithy/property-provider': 4.0.1 '@smithy/protocol-http': 5.0.1 - '@smithy/smithy-client': 4.1.2 + '@smithy/smithy-client': 4.1.3 '@smithy/types': 4.1.0 '@smithy/util-stream': 4.0.2 tslib: 2.8.1 @@ -4903,11 +4931,11 @@ snapshots: '@aws-sdk/core': 3.734.0 '@aws-sdk/types': 3.734.0 '@aws-sdk/util-arn-parser': 3.723.0 - '@smithy/core': 3.1.1 + '@smithy/core': 3.1.2 '@smithy/node-config-provider': 4.0.1 '@smithy/protocol-http': 5.0.1 '@smithy/signature-v4': 5.0.1 - '@smithy/smithy-client': 4.1.2 + '@smithy/smithy-client': 4.1.3 '@smithy/types': 4.1.0 '@smithy/util-config-provider': 4.0.0 '@smithy/util-middleware': 4.0.1 @@ -4926,7 +4954,7 @@ snapshots: '@aws-sdk/core': 3.734.0 '@aws-sdk/types': 3.734.0 '@aws-sdk/util-endpoints': 3.734.0 - '@smithy/core': 3.1.1 + '@smithy/core': 3.1.2 '@smithy/protocol-http': 5.0.1 '@smithy/types': 4.1.0 tslib: 2.8.1 @@ -4946,26 +4974,26 @@ snapshots: '@aws-sdk/util-user-agent-browser': 3.734.0 '@aws-sdk/util-user-agent-node': 3.734.0 '@smithy/config-resolver': 4.0.1 - '@smithy/core': 3.1.1 + '@smithy/core': 3.1.2 '@smithy/fetch-http-handler': 5.0.1 '@smithy/hash-node': 4.0.1 '@smithy/invalid-dependency': 4.0.1 '@smithy/middleware-content-length': 4.0.1 - '@smithy/middleware-endpoint': 4.0.2 - '@smithy/middleware-retry': 4.0.3 - '@smithy/middleware-serde': 4.0.1 + '@smithy/middleware-endpoint': 4.0.3 + '@smithy/middleware-retry': 4.0.4 + '@smithy/middleware-serde': 4.0.2 '@smithy/middleware-stack': 4.0.1 '@smithy/node-config-provider': 4.0.1 '@smithy/node-http-handler': 4.0.2 '@smithy/protocol-http': 5.0.1 - '@smithy/smithy-client': 4.1.2 + '@smithy/smithy-client': 4.1.3 '@smithy/types': 4.1.0 '@smithy/url-parser': 4.0.1 '@smithy/util-base64': 4.0.0 '@smithy/util-body-length-browser': 4.0.0 '@smithy/util-body-length-node': 4.0.0 - '@smithy/util-defaults-mode-browser': 4.0.3 - '@smithy/util-defaults-mode-node': 4.0.3 + '@smithy/util-defaults-mode-browser': 4.0.4 + '@smithy/util-defaults-mode-node': 4.0.4 '@smithy/util-endpoints': 3.0.1 '@smithy/util-middleware': 4.0.1 '@smithy/util-retry': 4.0.1 @@ -6103,7 +6131,18 @@ snapshots: '@smithy/core@3.1.1': dependencies: - '@smithy/middleware-serde': 4.0.1 + '@smithy/middleware-serde': 4.0.2 + '@smithy/protocol-http': 5.0.1 + '@smithy/types': 4.1.0 + '@smithy/util-body-length-browser': 4.0.0 + '@smithy/util-middleware': 4.0.1 + '@smithy/util-stream': 4.0.2 + '@smithy/util-utf8': 4.0.0 + tslib: 2.8.1 + + '@smithy/core@3.1.2': + dependencies: + '@smithy/middleware-serde': 4.0.2 '@smithy/protocol-http': 5.0.1 '@smithy/types': 4.1.0 '@smithy/util-body-length-browser': 4.0.0 @@ -6205,8 +6244,19 @@ snapshots: '@smithy/middleware-endpoint@4.0.2': dependencies: - '@smithy/core': 3.1.1 - '@smithy/middleware-serde': 4.0.1 + '@smithy/core': 3.1.2 + '@smithy/middleware-serde': 4.0.2 + '@smithy/node-config-provider': 4.0.1 + '@smithy/shared-ini-file-loader': 4.0.1 + '@smithy/types': 4.1.0 + '@smithy/url-parser': 4.0.1 + '@smithy/util-middleware': 4.0.1 + tslib: 2.8.1 + + '@smithy/middleware-endpoint@4.0.3': + dependencies: + '@smithy/core': 3.1.2 + '@smithy/middleware-serde': 4.0.2 '@smithy/node-config-provider': 4.0.1 '@smithy/shared-ini-file-loader': 4.0.1 '@smithy/types': 4.1.0 @@ -6219,7 +6269,19 @@ snapshots: '@smithy/node-config-provider': 4.0.1 '@smithy/protocol-http': 5.0.1 '@smithy/service-error-classification': 4.0.1 - '@smithy/smithy-client': 4.1.2 + '@smithy/smithy-client': 4.1.3 + '@smithy/types': 4.1.0 + '@smithy/util-middleware': 4.0.1 + '@smithy/util-retry': 4.0.1 + tslib: 2.8.1 + uuid: 9.0.1 + + '@smithy/middleware-retry@4.0.4': + dependencies: + '@smithy/node-config-provider': 4.0.1 + '@smithy/protocol-http': 5.0.1 + '@smithy/service-error-classification': 4.0.1 + '@smithy/smithy-client': 4.1.3 '@smithy/types': 4.1.0 '@smithy/util-middleware': 4.0.1 '@smithy/util-retry': 4.0.1 @@ -6231,6 +6293,11 @@ snapshots: '@smithy/types': 4.1.0 tslib: 2.8.1 + '@smithy/middleware-serde@4.0.2': + dependencies: + '@smithy/types': 4.1.0 + tslib: 2.8.1 + '@smithy/middleware-stack@4.0.1': dependencies: '@smithy/types': 4.1.0 @@ -6294,8 +6361,18 @@ snapshots: '@smithy/smithy-client@4.1.2': dependencies: - '@smithy/core': 3.1.1 - '@smithy/middleware-endpoint': 4.0.2 + '@smithy/core': 3.1.2 + '@smithy/middleware-endpoint': 4.0.3 + '@smithy/middleware-stack': 4.0.1 + '@smithy/protocol-http': 5.0.1 + '@smithy/types': 4.1.0 + '@smithy/util-stream': 4.0.2 + tslib: 2.8.1 + + '@smithy/smithy-client@4.1.3': + dependencies: + '@smithy/core': 3.1.2 + '@smithy/middleware-endpoint': 4.0.3 '@smithy/middleware-stack': 4.0.1 '@smithy/protocol-http': 5.0.1 '@smithy/types': 4.1.0 @@ -6343,7 +6420,15 @@ snapshots: '@smithy/util-defaults-mode-browser@4.0.3': dependencies: '@smithy/property-provider': 4.0.1 - '@smithy/smithy-client': 4.1.2 + '@smithy/smithy-client': 4.1.3 + '@smithy/types': 4.1.0 + bowser: 2.11.0 + tslib: 2.8.1 + + '@smithy/util-defaults-mode-browser@4.0.4': + dependencies: + '@smithy/property-provider': 4.0.1 + '@smithy/smithy-client': 4.1.3 '@smithy/types': 4.1.0 bowser: 2.11.0 tslib: 2.8.1 @@ -6354,7 +6439,17 @@ snapshots: '@smithy/credential-provider-imds': 4.0.1 '@smithy/node-config-provider': 4.0.1 '@smithy/property-provider': 4.0.1 - '@smithy/smithy-client': 4.1.2 + '@smithy/smithy-client': 4.1.3 + '@smithy/types': 4.1.0 + tslib: 2.8.1 + + '@smithy/util-defaults-mode-node@4.0.4': + dependencies: + '@smithy/config-resolver': 4.0.1 + '@smithy/credential-provider-imds': 4.0.1 + '@smithy/node-config-provider': 4.0.1 + '@smithy/property-provider': 4.0.1 + '@smithy/smithy-client': 4.1.3 '@smithy/types': 4.1.0 tslib: 2.8.1