diff --git a/src/build/functions/edge.ts b/src/build/functions/edge.ts index 75fd3bcef8..a26ee857c9 100644 --- a/src/build/functions/edge.ts +++ b/src/build/functions/edge.ts @@ -210,7 +210,7 @@ const copyHandlerDependenciesForNodeMiddleware = async (ctx: PluginContext) => { const entry = 'server/middleware.js' const nft = `${entry}.nft.json` - const nftFilesPath = join(process.cwd(), ctx.nextDistDir, nft) + const nftFilesPath = join(process.cwd(), ctx.distDir, nft) const nftManifest = JSON.parse(await readFile(nftFilesPath, 'utf8')) const files: string[] = nftManifest.files.map((file: string) => join('server', file)) diff --git a/tests/smoke/deploy.test.ts b/tests/smoke/deploy.test.ts index de97122d9f..abee3ff93b 100644 --- a/tests/smoke/deploy.test.ts +++ b/tests/smoke/deploy.test.ts @@ -1,5 +1,6 @@ import { afterEach, describe, expect, test } from 'vitest' import { Fixture, fixtureFactories } from '../utils/create-e2e-fixture' +import { nextVersionSatisfies } from '../utils/next-version-helpers.mjs' const usedFixtures = new Set() /** @@ -37,6 +38,19 @@ async function smokeTest(createFixture: () => Promise) { await expect(body).toContain('SSR: yes') } +if (nextVersionSatisfies('>=16.0.0')) { + test('npm monorepo with proxy / node middleware', async () => { + // proxy ~= node middleware + const fixture = await selfCleaningFixtureFactories.npmMonorepoProxy() + + const response = await fetch(fixture.url) + expect(response.status).toBe(200) + + const body = await response.json() + expect(body).toEqual({ proxy: true }) + }) +} + test('yarn@3 monorepo with pnpm linker', async () => { await smokeTest(selfCleaningFixtureFactories.yarnMonorepoWithPnpmLinker) }) diff --git a/tests/smoke/fixtures/npm-monorepo-proxy/apps/site/next.config.js b/tests/smoke/fixtures/npm-monorepo-proxy/apps/site/next.config.js new file mode 100644 index 0000000000..5cd8cc341f --- /dev/null +++ b/tests/smoke/fixtures/npm-monorepo-proxy/apps/site/next.config.js @@ -0,0 +1,6 @@ +/** @type {import('next').NextConfig} */ +const nextConfig = { + output: 'standalone', +} + +module.exports = nextConfig diff --git a/tests/smoke/fixtures/npm-monorepo-proxy/apps/site/package.json b/tests/smoke/fixtures/npm-monorepo-proxy/apps/site/package.json new file mode 100644 index 0000000000..f3137768af --- /dev/null +++ b/tests/smoke/fixtures/npm-monorepo-proxy/apps/site/package.json @@ -0,0 +1,13 @@ +{ + "name": "@apps/site", + "version": "0.1.0", + "private": true, + "scripts": { + "build": "next build" + }, + "dependencies": { + "next": "latest", + "react": "^18.2.0", + "react-dom": "^18.2.0" + } +} diff --git a/tests/smoke/fixtures/npm-monorepo-proxy/apps/site/pages/index.js b/tests/smoke/fixtures/npm-monorepo-proxy/apps/site/pages/index.js new file mode 100644 index 0000000000..eaf17aeb3a --- /dev/null +++ b/tests/smoke/fixtures/npm-monorepo-proxy/apps/site/pages/index.js @@ -0,0 +1,7 @@ +export default function Home() { + return ( +
+ This should never render, because proxy/middleware always respond before handling pages +
+ ) +} diff --git a/tests/smoke/fixtures/npm-monorepo-proxy/apps/site/proxy.ts b/tests/smoke/fixtures/npm-monorepo-proxy/apps/site/proxy.ts new file mode 100644 index 0000000000..2cd076a129 --- /dev/null +++ b/tests/smoke/fixtures/npm-monorepo-proxy/apps/site/proxy.ts @@ -0,0 +1,6 @@ +import type { NextRequest } from 'next/server' +import { NextResponse } from 'next/server' + +export async function proxy(request: NextRequest) { + return NextResponse.json({ proxy: true }) +} diff --git a/tests/smoke/fixtures/npm-monorepo-proxy/package.json b/tests/smoke/fixtures/npm-monorepo-proxy/package.json new file mode 100644 index 0000000000..06afd549b7 --- /dev/null +++ b/tests/smoke/fixtures/npm-monorepo-proxy/package.json @@ -0,0 +1,14 @@ +{ + "name": "npm-monorepo-proxy", + "private": true, + "scripts": { + "build": "npm run build --workspace @apps/site" + }, + "engines": { + "node": ">=18" + }, + "packageManager": "npm@10.2.3", + "workspaces": [ + "apps/*" + ] +} diff --git a/tests/utils/create-e2e-fixture.ts b/tests/utils/create-e2e-fixture.ts index 0af1e20a1d..961a446bfc 100644 --- a/tests/utils/create-e2e-fixture.ts +++ b/tests/utils/create-e2e-fixture.ts @@ -629,6 +629,13 @@ export const fixtureFactories = { publishDirectory: 'apps/site/.next', smoke: true, }), + npmMonorepoProxy: () => + createE2EFixture('npm-monorepo-proxy', { + buildCommand: 'npm run build --workspace @apps/site', + packagePath: 'apps/site', + publishDirectory: 'apps/site/.next', + smoke: true, + }), dynamicCms: () => createE2EFixture('dynamic-cms'), after: () => createE2EFixture('after'), }