diff --git a/.changeset/good-meals-think.md b/.changeset/good-meals-think.md new file mode 100644 index 00000000..afae1c15 --- /dev/null +++ b/.changeset/good-meals-think.md @@ -0,0 +1,5 @@ +--- +"@opennextjs/cloudflare": patch +--- + +fix the encoding of \_\_NEXT_PRIVATE_STANDALONE_CONFIG diff --git a/examples/api/app/api/buildid/route.ts b/examples/api/app/api/buildid/route.ts new file mode 100644 index 00000000..0c95b72b --- /dev/null +++ b/examples/api/app/api/buildid/route.ts @@ -0,0 +1,9 @@ +// Use headers to force a dynamic response +import { headers } from "next/headers"; + +export async function GET() { + const nextConfig = process.env.__NEXT_PRIVATE_STANDALONE_CONFIG + ? JSON.parse(process.env.__NEXT_PRIVATE_STANDALONE_CONFIG) + : undefined; + return Response.json({ nextConfig, headers: headers() }); +} diff --git a/examples/api/e2e/cloudflare.spec.ts b/examples/api/e2e/cloudflare.spec.ts new file mode 100644 index 00000000..c2b257ca --- /dev/null +++ b/examples/api/e2e/cloudflare.spec.ts @@ -0,0 +1,14 @@ +/** + * Cloudflare specific tests. + * + * The tests in this file do not run on Node (`next dev`). + */ + +import { test, expect } from "@playwright/test"; + +test("NextConfig", async ({ page }) => { + const res = await page.request.get("/api/buildid"); + expect(res.status()).toEqual(200); + const { nextConfig } = await res.json(); + expect(nextConfig.output).toEqual("standalone"); +}); diff --git a/examples/api/e2e/playwright.dev.config.ts b/examples/api/e2e/playwright.dev.config.ts index b14e729e..e1675b2f 100644 --- a/examples/api/e2e/playwright.dev.config.ts +++ b/examples/api/e2e/playwright.dev.config.ts @@ -8,6 +8,7 @@ declare const process: typeof nodeProcess; */ export default defineConfig({ testDir: "./", + testIgnore: "cloudflare.spec.ts", /* Run tests in files in parallel */ fullyParallel: true, /* Fail the build on CI if you accidentally left test.only in the source code. */ diff --git a/examples/next-partial-prerendering/package.json b/examples/next-partial-prerendering/package.json index cd05edf9..2926ddbd 100644 --- a/examples/next-partial-prerendering/package.json +++ b/examples/next-partial-prerendering/package.json @@ -1,5 +1,6 @@ { "private": true, + "name": "next-partial-prerendering", "scripts": { "build": "next build", "dev": "next dev --turbo", diff --git a/packages/cloudflare/src/cli/build/bundle-server.ts b/packages/cloudflare/src/cli/build/bundle-server.ts index d1d78b60..a6feb4ef 100644 --- a/packages/cloudflare/src/cli/build/bundle-server.ts +++ b/packages/cloudflare/src/cli/build/bundle-server.ts @@ -92,7 +92,7 @@ export async function bundleServer(buildOpts: BuildOptions): Promise { }, define: { // config file used by Next.js, see: https://github.com/vercel/next.js/blob/68a7128/packages/next/src/build/utils.ts#L2137-L2139 - "process.env.__NEXT_PRIVATE_STANDALONE_CONFIG": `${JSON.stringify(nextConfig)}`, + "process.env.__NEXT_PRIVATE_STANDALONE_CONFIG": JSON.stringify(JSON.stringify(nextConfig)), // Next.js tried to access __dirname so we need to define it __dirname: '""', // Note: we need the __non_webpack_require__ variable declared as it is used by next-server: