Skip to content

Commit ff5479e

Browse files
hrishikesh-kpieh
andauthored
fix: incorrect output path of middleware nft for Next.js 16 (#3211)
Co-authored-by: Michal Piechowiak <misiek.piechowiak@gmail.com>
1 parent ec69232 commit ff5479e

File tree

8 files changed

+68
-1
lines changed

8 files changed

+68
-1
lines changed

src/build/functions/edge.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ const copyHandlerDependenciesForNodeMiddleware = async (ctx: PluginContext) => {
210210

211211
const entry = 'server/middleware.js'
212212
const nft = `${entry}.nft.json`
213-
const nftFilesPath = join(process.cwd(), ctx.nextDistDir, nft)
213+
const nftFilesPath = join(process.cwd(), ctx.distDir, nft)
214214
const nftManifest = JSON.parse(await readFile(nftFilesPath, 'utf8'))
215215

216216
const files: string[] = nftManifest.files.map((file: string) => join('server', file))

tests/smoke/deploy.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { afterEach, describe, expect, test } from 'vitest'
22
import { Fixture, fixtureFactories } from '../utils/create-e2e-fixture'
3+
import { nextVersionSatisfies } from '../utils/next-version-helpers.mjs'
34

45
const usedFixtures = new Set<Fixture>()
56
/**
@@ -37,6 +38,19 @@ async function smokeTest(createFixture: () => Promise<Fixture>) {
3738
await expect(body).toContain('SSR: yes')
3839
}
3940

41+
if (nextVersionSatisfies('>=16.0.0')) {
42+
test('npm monorepo with proxy / node middleware', async () => {
43+
// proxy ~= node middleware
44+
const fixture = await selfCleaningFixtureFactories.npmMonorepoProxy()
45+
46+
const response = await fetch(fixture.url)
47+
expect(response.status).toBe(200)
48+
49+
const body = await response.json()
50+
expect(body).toEqual({ proxy: true })
51+
})
52+
}
53+
4054
test('yarn@3 monorepo with pnpm linker', async () => {
4155
await smokeTest(selfCleaningFixtureFactories.yarnMonorepoWithPnpmLinker)
4256
})
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/** @type {import('next').NextConfig} */
2+
const nextConfig = {
3+
output: 'standalone',
4+
}
5+
6+
module.exports = nextConfig
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "@apps/site",
3+
"version": "0.1.0",
4+
"private": true,
5+
"scripts": {
6+
"build": "next build"
7+
},
8+
"dependencies": {
9+
"next": "latest",
10+
"react": "^18.2.0",
11+
"react-dom": "^18.2.0"
12+
}
13+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default function Home() {
2+
return (
3+
<main>
4+
This should never render, because proxy/middleware always respond before handling pages
5+
</main>
6+
)
7+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import type { NextRequest } from 'next/server'
2+
import { NextResponse } from 'next/server'
3+
4+
export async function proxy(request: NextRequest) {
5+
return NextResponse.json({ proxy: true })
6+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "npm-monorepo-proxy",
3+
"private": true,
4+
"scripts": {
5+
"build": "npm run build --workspace @apps/site"
6+
},
7+
"engines": {
8+
"node": ">=18"
9+
},
10+
"packageManager": "npm@10.2.3",
11+
"workspaces": [
12+
"apps/*"
13+
]
14+
}

tests/utils/create-e2e-fixture.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,13 @@ export const fixtureFactories = {
629629
publishDirectory: 'apps/site/.next',
630630
smoke: true,
631631
}),
632+
npmMonorepoProxy: () =>
633+
createE2EFixture('npm-monorepo-proxy', {
634+
buildCommand: 'npm run build --workspace @apps/site',
635+
packagePath: 'apps/site',
636+
publishDirectory: 'apps/site/.next',
637+
smoke: true,
638+
}),
632639
dynamicCms: () => createE2EFixture('dynamic-cms'),
633640
after: () => createE2EFixture('after'),
634641
}

0 commit comments

Comments
 (0)