Skip to content

Commit

Permalink
Fix middleware at root in standalone mode
Browse files Browse the repository at this point in the history
  • Loading branch information
skirsten committed Jan 6, 2022
1 parent 48c0bc8 commit 4b36be7
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { NextResponse } from 'next/server'

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

0 comments on commit 4b36be7

Please sign in to comment.