Unverified Commit 6f5bfc1b authored by Simon Kirsten's avatar Simon Kirsten Committed by GitHub

Fix middleware at root in standalone mode (#33053)

Fixes [a small bug](https://github.com/vercel/next.js/pull/32967#issuecomment-1006277236) that caused the build to crash if a _middleware is present at the root of the project and standalone mode is enabled.
parent efabf81e
...@@ -1207,7 +1207,7 @@ export async function copyTracedFiles( ...@@ -1207,7 +1207,7 @@ export async function copyTracedFiles(
for (const page of pageKeys) { for (const page of pageKeys) {
if (MIDDLEWARE_ROUTE.test(page)) { if (MIDDLEWARE_ROUTE.test(page)) {
const { files } = const { files } =
middlewareManifest.middleware[page.replace(/\/_middleware$/, '')] middlewareManifest.middleware[page.replace(/\/_middleware$/, '') || '/']
for (const file of files) { for (const file of files) {
const originalPath = path.join(distDir, file) const originalPath = path.join(distDir, file)
......
...@@ -121,6 +121,11 @@ describe('should set-up next', () => { ...@@ -121,6 +121,11 @@ describe('should set-up next', () => {
) )
) )
).toBe(true) ).toBe(true)
expect(
await fs.pathExists(
join(next.testDir, 'standalone/.next/server/pages/_middleware.js')
)
).toBe(true)
}) })
it('should output required-server-files manifest correctly', async () => { it('should output required-server-files manifest correctly', async () => {
......
import { NextResponse } from 'next/server'
export async function middleware(req) {
return NextResponse.next()
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment