-
Notifications
You must be signed in to change notification settings - Fork 89
fix: preserve original path after middleware rewrite #2177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import * as React from 'react' | ||
|
||
const Page = ({ pageLocale }) => { | ||
return <div>Locale: {pageLocale}</div> | ||
} | ||
|
||
export async function getServerSideProps({ locale }) { | ||
return { | ||
props: { | ||
pageLocale: locale, | ||
}, | ||
} | ||
} | ||
|
||
export default Page |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
import { PrerenderManifest } from 'next/dist/build' | ||
// eslint-disable-next-line n/no-deprecated-api -- this is what Next.js uses as well | ||
import { parse } from 'url' | ||
|
||
import type { PrerenderManifest } from 'next/dist/build' | ||
import type { BaseNextResponse } from 'next/dist/server/base-http' | ||
import type { NodeRequestHandler, Options } from 'next/dist/server/next-server' | ||
|
||
|
@@ -36,6 +39,10 @@ const getNetlifyNextServer = (NextServer: NextServerType) => { | |
public getRequestHandler(): NodeRequestHandler { | ||
const handler = super.getRequestHandler() | ||
return async (req, res, parsedUrl) => { | ||
if (!parsedUrl && typeof req?.headers?.['x-middleware-rewrite'] === 'string') { | ||
parsedUrl = parse(req.headers['x-middleware-rewrite'], true) | ||
} | ||
|
||
Comment on lines
+42
to
+45
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Next does same parsing in https://github.com/vercel/next.js/blob/7dfa56c7141ae2556af0d7fd837e0af686d8fa55/packages/next/src/server/base-server.ts#L662-L665 and later on does a lot of checking on it and potentially messing with it. Passing |
||
// preserve the URL before Next.js mutates it for i18n | ||
const { url, headers } = req | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.