diff --git a/.changeset/brave-birds-flash.md b/.changeset/brave-birds-flash.md new file mode 100644 index 0000000..a7a650f --- /dev/null +++ b/.changeset/brave-birds-flash.md @@ -0,0 +1,7 @@ +--- +"@opennextjs/cloudflare": patch +--- + +example: Add vercel blog starter + +Update the examples with vercel blog starter and adapt it to run on cf workers diff --git a/examples/vercel-blog-starter/.gitignore b/examples/vercel-blog-starter/.gitignore index fd3dbb5..13af320 100644 --- a/examples/vercel-blog-starter/.gitignore +++ b/examples/vercel-blog-starter/.gitignore @@ -34,3 +34,7 @@ yarn-error.log* # typescript *.tsbuildinfo next-env.d.ts + +#cf workers +.wrangler +.worker-next \ No newline at end of file diff --git a/examples/vercel-blog-starter/next.config.mjs b/examples/vercel-blog-starter/next.config.mjs new file mode 100644 index 0000000..4678774 --- /dev/null +++ b/examples/vercel-blog-starter/next.config.mjs @@ -0,0 +1,4 @@ +/** @type {import('next').NextConfig} */ +const nextConfig = {}; + +export default nextConfig; diff --git a/examples/vercel-blog-starter/package.json b/examples/vercel-blog-starter/package.json index 8293f65..e0b5620 100644 --- a/examples/vercel-blog-starter/package.json +++ b/examples/vercel-blog-starter/package.json @@ -1,9 +1,13 @@ { + "name": "vercel-blog-starter", "private": true, "scripts": { "dev": "next", "build": "next build", - "start": "next start" + "start": "next start", + "build:worker": "cloudflare", + "dev:worker": "wrangler dev --port 8773", + "preview:worker": "pnpm build:worker && pnpm dev:worker" }, "dependencies": { "classnames": "^2.5.1", @@ -16,12 +20,14 @@ "remark-html": "^16.0.1" }, "devDependencies": { + "@opennextjs/cloudflare": "workspace:*", "@types/node": "^20.14.8", "@types/react": "^18.3.3", "@types/react-dom": "^18.3.0", "autoprefixer": "^10.4.19", "postcss": "^8.4.38", "tailwindcss": "^3.4.4", - "typescript": "^5.5.2" + "typescript": "^5.5.2", + "wrangler": "^3.80.4" } } diff --git a/examples/vercel-blog-starter/wrangler.toml b/examples/vercel-blog-starter/wrangler.toml new file mode 100644 index 0000000..ceb8a92 --- /dev/null +++ b/examples/vercel-blog-starter/wrangler.toml @@ -0,0 +1,9 @@ +#:schema node_modules/wrangler/config-schema.json +name = "vercel-blog-starter-on-workers" +main = ".worker-next/index.mjs" + +compatibility_date = "2024-09-23" +compatibility_flags = ["nodejs_compat"] + +# Use the new Workers + Assets to host the static frontend files +assets = { directory = ".worker-next/assets", binding = "ASSETS" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 645897c..0458877 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -188,6 +188,9 @@ importers: specifier: ^16.0.1 version: 16.0.1 devDependencies: + '@opennextjs/cloudflare': + specifier: workspace:* + version: link:../../packages/cloudflare '@types/node': specifier: ^20.14.8 version: 20.14.12 @@ -209,6 +212,9 @@ importers: typescript: specifier: ^5.5.2 version: 5.5.4 + wrangler: + specifier: ^3.80.4 + version: 3.80.4 examples/vercel-commerce: dependencies: @@ -419,34 +425,68 @@ packages: cpu: [x64] os: [darwin] + '@cloudflare/workerd-darwin-64@1.20241004.0': + resolution: {integrity: sha512-c2afR486NXDRcPm7RaTSRDnffFklPCXde/IeNVhEhBJ8O+pQhBOdDcGIy8zXPwMu0CYga0iHNZmpbsl+ZcHttA==} + engines: {node: '>=16'} + cpu: [x64] + os: [darwin] + '@cloudflare/workerd-darwin-arm64@1.20240925.0': resolution: {integrity: sha512-MiQ6uUmCXjsXgWNV+Ock2tp2/tYqNJGzjuaH6jFioeRF+//mz7Tv7J7EczOL4zq+TH8QFOh0/PUsLyazIWVGng==} engines: {node: '>=16'} cpu: [arm64] os: [darwin] + '@cloudflare/workerd-darwin-arm64@1.20241004.0': + resolution: {integrity: sha512-siD9fexv5lr2IpBczWV7OPgJvHj8/fJUrRAYCMcBURkfiwssK91coQeZlN1NdQ85aYELVgxDFoG+p86OS+ZzLw==} + engines: {node: '>=16'} + cpu: [arm64] + os: [darwin] + '@cloudflare/workerd-linux-64@1.20240925.0': resolution: {integrity: sha512-Rjix8jsJMfsInmq3Hm3fmiRQ+rwzuWRPV1pg/OWhMSfNP7Qp2RCU+RGkhgeR9Z5eNAje0Sn2BMrFq4RvF9/yRA==} engines: {node: '>=16'} cpu: [x64] os: [linux] + '@cloudflare/workerd-linux-64@1.20241004.0': + resolution: {integrity: sha512-EtKGXO5fzRgX6UhDDLhjjEsB1QtliHb12zavZ/S0C8hKPz76II7MQ3Lls9kfB62fbdMP8L6vcqWPObEUcw6GSw==} + engines: {node: '>=16'} + cpu: [x64] + os: [linux] + '@cloudflare/workerd-linux-arm64@1.20240925.0': resolution: {integrity: sha512-VYIPeMHQRtbwQoIjUwS/zULlywPxyDvo46XkTpIW5MScEChfqHvAYviQ7TzYGx6Q+gmZmN+DUB2KOMx+MEpCxA==} engines: {node: '>=16'} cpu: [arm64] os: [linux] + '@cloudflare/workerd-linux-arm64@1.20241004.0': + resolution: {integrity: sha512-XO7VBE1YaFf/o9tKO1PqDqaxkU2eAR2DLX7R0+R8p+q92sUDXyoxo48T3yJDfxWndnKJ6hSJfvKanw3Mq9Tisw==} + engines: {node: '>=16'} + cpu: [arm64] + os: [linux] + '@cloudflare/workerd-windows-64@1.20240925.0': resolution: {integrity: sha512-C8peGvaU5R51bIySi1VbyfRgwNSSRknqoFSnSbSBI3uTN3THTB3UnmRKy7GXJDmyjgXuT9Pcs1IgaWNubLtNtw==} engines: {node: '>=16'} cpu: [x64] os: [win32] + '@cloudflare/workerd-windows-64@1.20241004.0': + resolution: {integrity: sha512-o+TmCYGq58jNUDbG73xOvd648XvJ2TicI++2BBoySklJXG6f4But5AwA8TxQgmeujR3vpBjPZKexEzcZSUOTtA==} + engines: {node: '>=16'} + cpu: [x64] + os: [win32] + '@cloudflare/workers-shared@0.5.4': resolution: {integrity: sha512-PNL/0TjKRdUHa1kwgVdqUNJVZ9ez4kacsi8omz+gv859EvJmsVuGiMAClY2YfJnC9LVKhKCcjqmFgKNXG9/IXA==} engines: {node: '>=16.7.0'} + '@cloudflare/workers-shared@0.6.0': + resolution: {integrity: sha512-rfUCvb3hx4AsvdUZsxgk9lmgEnQehqV3jdtXLP/Xr0+P56n11T/0nXNMzmn7Nnv+IJFOV6X9NmFhuMz4sBPw7w==} + engines: {node: '>=16.7.0'} + '@cloudflare/workers-types@4.20240925.0': resolution: {integrity: sha512-KpqyRWvanEuXgBTKYFzRp4NsWOEcswxjsPRSre1zYQcODmc8PUrraVHQUmgvkJgv3FzB+vI9xm7J6oE4MmZHCA==} @@ -3019,6 +3059,11 @@ packages: engines: {node: '>=16.13'} hasBin: true + miniflare@3.20241004.0: + resolution: {integrity: sha512-QSSmCR2V1AJnnpYwlyLXobKLSGiY1FlAiZYULMdGgOUThV7HJeSysDxsmPmrH+D4GQbmUERnmDdB6M6Rrz7uPg==} + engines: {node: '>=16.13'} + hasBin: true + minimatch@10.0.1: resolution: {integrity: sha512-ethXTt3SGGR+95gudmqJ1eNhRO7eGEGIgYA9vnPatK4/etz2MEVDno5GMCibdMTuBMyElzIlgxMna3K94XDIDQ==} engines: {node: 20 || >=22} @@ -4081,6 +4126,9 @@ packages: unenv-nightly@2.0.0-20240919-125358-9a64854: resolution: {integrity: sha512-XjsgUTrTHR7iw+k/SRTNjh6EQgwpC9voygnoCJo5kh4hKqsSDHUW84MhL9EsHTNfLctvVBHaSw8e2k3R2fKXsQ==} + unenv-nightly@2.0.0-20241009-125958-e8ea22f: + resolution: {integrity: sha512-hRxmKz1iSVRmuFx/vBdPsx7rX4o7Cas9vdjDNeUeWpQTK2LzU3Xy3Jz0zbo7MJX0bpqo/LEFCA+GPwsbl6zKEQ==} + unified@11.0.5: resolution: {integrity: sha512-xKvGhPWw3k84Qjh8bI3ZeJjqnyadK+GEFtazSfZv/rKeTkTjOJho6mFqh2SM96iIcZokxiOpg78GazTSg8+KHA==} @@ -4240,6 +4288,11 @@ packages: engines: {node: '>=16'} hasBin: true + workerd@1.20241004.0: + resolution: {integrity: sha512-TCFJ7Zw7svR3adg1fnlPWj/yXhjBnQloLEIJqdu57hli/GsgwlbomwrbM3mdMgbS+K9zYeaYqknXiBN0EXk3QQ==} + engines: {node: '>=16'} + hasBin: true + wrangler@3.78.10: resolution: {integrity: sha512-Q8Ia0xz0RCzj5X7TMIEQ/EbADSG2cWPmTDRaulGSWnYqfIlFyKoxl7Zx1XXCo1EkDcKfSpX6TZa22pCDmtl4LA==} engines: {node: '>=16.17.0'} @@ -4250,6 +4303,16 @@ packages: '@cloudflare/workers-types': optional: true + wrangler@3.80.4: + resolution: {integrity: sha512-DyNvShtVH3k7ZyBndlIiwyRDXqtHr3g01hxwn4FfwKlAaT6EL0wb3KL3UGbsdpeM/xbJiUQxFQ4WuFBWgZS18Q==} + engines: {node: '>=16.17.0'} + hasBin: true + peerDependencies: + '@cloudflare/workers-types': ^4.20241004.0 + peerDependenciesMeta: + '@cloudflare/workers-types': + optional: true + wrap-ansi@7.0.0: resolution: {integrity: sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==} engines: {node: '>=10'} @@ -4472,23 +4535,43 @@ snapshots: '@cloudflare/workerd-darwin-64@1.20240925.0': optional: true + '@cloudflare/workerd-darwin-64@1.20241004.0': + optional: true + '@cloudflare/workerd-darwin-arm64@1.20240925.0': optional: true + '@cloudflare/workerd-darwin-arm64@1.20241004.0': + optional: true + '@cloudflare/workerd-linux-64@1.20240925.0': optional: true + '@cloudflare/workerd-linux-64@1.20241004.0': + optional: true + '@cloudflare/workerd-linux-arm64@1.20240925.0': optional: true + '@cloudflare/workerd-linux-arm64@1.20241004.0': + optional: true + '@cloudflare/workerd-windows-64@1.20240925.0': optional: true + '@cloudflare/workerd-windows-64@1.20241004.0': + optional: true + '@cloudflare/workers-shared@0.5.4': dependencies: mime: 3.0.0 zod: 3.23.8 + '@cloudflare/workers-shared@0.6.0': + dependencies: + mime: 3.0.0 + zod: 3.23.8 + '@cloudflare/workers-types@4.20240925.0': {} '@cspotcode/source-map-support@0.8.1': @@ -7247,6 +7330,25 @@ snapshots: - supports-color - utf-8-validate + miniflare@3.20241004.0: + dependencies: + '@cspotcode/source-map-support': 0.8.1 + acorn: 8.12.1 + acorn-walk: 8.3.3 + capnp-ts: 0.7.0 + exit-hook: 2.2.1 + glob-to-regexp: 0.4.1 + stoppable: 1.1.0 + undici: 5.28.4 + workerd: 1.20241004.0 + ws: 8.18.0 + youch: 3.3.3 + zod: 3.23.8 + transitivePeerDependencies: + - bufferutil + - supports-color + - utf-8-validate + minimatch@10.0.1: dependencies: brace-expansion: 2.0.1 @@ -8366,6 +8468,13 @@ snapshots: pathe: 1.1.2 ufo: 1.5.4 + unenv-nightly@2.0.0-20241009-125958-e8ea22f: + dependencies: + defu: 6.1.4 + ohash: 1.1.4 + pathe: 1.1.2 + ufo: 1.5.4 + unified@11.0.5: dependencies: '@types/unist': 3.0.3 @@ -8563,6 +8672,14 @@ snapshots: '@cloudflare/workerd-linux-arm64': 1.20240925.0 '@cloudflare/workerd-windows-64': 1.20240925.0 + workerd@1.20241004.0: + optionalDependencies: + '@cloudflare/workerd-darwin-64': 1.20241004.0 + '@cloudflare/workerd-darwin-arm64': 1.20241004.0 + '@cloudflare/workerd-linux-64': 1.20241004.0 + '@cloudflare/workerd-linux-arm64': 1.20241004.0 + '@cloudflare/workerd-windows-64': 1.20241004.0 + wrangler@3.78.10(@cloudflare/workers-types@4.20240925.0): dependencies: '@cloudflare/kv-asset-handler': 0.3.4 @@ -8590,6 +8707,32 @@ snapshots: - supports-color - utf-8-validate + wrangler@3.80.4: + dependencies: + '@cloudflare/kv-asset-handler': 0.3.4 + '@cloudflare/workers-shared': 0.6.0 + '@esbuild-plugins/node-globals-polyfill': 0.2.3(esbuild@0.17.19) + '@esbuild-plugins/node-modules-polyfill': 0.2.2(esbuild@0.17.19) + blake3-wasm: 2.1.5 + chokidar: 3.6.0 + esbuild: 0.17.19 + miniflare: 3.20241004.0 + nanoid: 3.3.7 + path-to-regexp: 6.3.0 + resolve: 1.22.8 + resolve.exports: 2.0.2 + selfsigned: 2.4.1 + source-map: 0.6.1 + unenv: unenv-nightly@2.0.0-20241009-125958-e8ea22f + workerd: 1.20241004.0 + xxhash-wasm: 1.0.2 + optionalDependencies: + fsevents: 2.3.3 + transitivePeerDependencies: + - bufferutil + - supports-color + - utf-8-validate + wrap-ansi@7.0.0: dependencies: ansi-styles: 4.3.0