Skip to content

Commit

Permalink
Fix middleware at root in standalone mode (#33053)
Browse files Browse the repository at this point in the history
Fixes [a small bug](#32967 (comment)) that caused the build to crash if a _middleware is present at the root of the project and standalone mode is enabled.
  • Loading branch information
skirsten committed Jan 6, 2022
1 parent efabf81 commit 6f5bfc1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/next/build/utils.ts
Expand Up @@ -1207,7 +1207,7 @@ export async function copyTracedFiles(
for (const page of pageKeys) {
if (MIDDLEWARE_ROUTE.test(page)) {
const { files } =
middlewareManifest.middleware[page.replace(/\/_middleware$/, '')]
middlewareManifest.middleware[page.replace(/\/_middleware$/, '') || '/']

for (const file of files) {
const originalPath = path.join(distDir, file)
Expand Down
5 changes: 5 additions & 0 deletions test/production/required-server-files.test.ts
Expand Up @@ -121,6 +121,11 @@ describe('should set-up next', () => {
)
)
).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 () => {
Expand Down
5 changes: 5 additions & 0 deletions test/production/required-server-files/pages/_middleware.js
@@ -0,0 +1,5 @@
import { NextResponse } from 'next/server'

export async function middleware(req) {
return NextResponse.next()
}

0 comments on commit 6f5bfc1

Please sign in to comment.