Skip to content

Commit e745eba

Browse files
committed
fix: pass our own parsedUrl on middleware rewrites
1 parent ba2583e commit e745eba

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

packages/runtime/src/templates/server.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { PrerenderManifest } from 'next/dist/build'
1+
// eslint-disable-next-line n/no-deprecated-api -- this is what Next.js uses as well
2+
import { parse } from 'url'
3+
4+
import type { PrerenderManifest } from 'next/dist/build'
25
import type { BaseNextResponse } from 'next/dist/server/base-http'
36
import type { NodeRequestHandler, Options } from 'next/dist/server/next-server'
47

@@ -36,6 +39,10 @@ const getNetlifyNextServer = (NextServer: NextServerType) => {
3639
public getRequestHandler(): NodeRequestHandler {
3740
const handler = super.getRequestHandler()
3841
return async (req, res, parsedUrl) => {
42+
if (!parsedUrl && typeof req?.headers?.['x-middleware-rewrite'] === 'string') {
43+
parsedUrl = parse(req.headers['x-middleware-rewrite'], true)
44+
}
45+
3946
// preserve the URL before Next.js mutates it for i18n
4047
const { url, headers } = req
4148

0 commit comments

Comments
 (0)