-
Notifications
You must be signed in to change notification settings - Fork 91
fix: support skipProxyUrlNormalize #3190
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
Merged
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| module.exports = { | ||
| output: 'standalone', | ||
| distDir: '.next', | ||
| generateBuildId: () => 'build-id', | ||
| i18n: { | ||
| locales: ['en', 'fr', 'nl', 'es'], | ||
| defaultLocale: 'en', | ||
| }, | ||
| skipProxyUrlNormalize: true, | ||
| experimental: { | ||
| clientRouterFilter: true, | ||
| clientRouterFilterRedirects: true, | ||
| }, | ||
| redirects() { | ||
| return [ | ||
| { | ||
| source: '/to-new', | ||
| destination: '/dynamic/new', | ||
| permanent: false, | ||
| }, | ||
| ] | ||
| }, | ||
| outputFileTracingRoot: __dirname, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| { | ||
| "name": "proxy-i18n-skip-normalize", | ||
| "version": "0.1.0", | ||
| "private": true, | ||
| "scripts": { | ||
| "postinstall": "npm run build", | ||
| "dev": "next dev", | ||
| "build": "next build" | ||
| }, | ||
| "dependencies": { | ||
| "next": "latest", | ||
| "react": "18.2.0", | ||
| "react-dom": "18.2.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/react": "18.2.47" | ||
| }, | ||
| "test": { | ||
| "dependencies": { | ||
| "next": ">=16.0.0-alpha.0" | ||
| } | ||
| } | ||
| } |
15 changes: 15 additions & 0 deletions
15
tests/fixtures/proxy-i18n-skip-normalize/pages/dynamic/[slug].js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| export default function Account({ slug }) { | ||
| return ( | ||
| <p id="dynamic" className="title"> | ||
| Welcome to a /dynamic/[slug]: {slug} | ||
| </p> | ||
| ) | ||
| } | ||
|
|
||
| export function getServerSideProps({ params }) { | ||
| return { | ||
| props: { | ||
| slug: params.slug, | ||
| }, | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import type { NextRequest } from 'next/server' | ||
| import { NextResponse } from 'next/server' | ||
|
|
||
| export async function proxy(request: NextRequest) { | ||
| const response = NextResponse.next() | ||
|
|
||
| if (response) { | ||
| response.headers.append('Deno' in globalThis ? 'x-deno' : 'x-node', Date.now().toString()) | ||
| // report Next.js Middleware Runtime (not the execution runtime, but target runtime) | ||
| // @ts-expect-error EdgeRuntime global not declared | ||
| response.headers.append('x-runtime', typeof EdgeRuntime !== 'undefined' ? EdgeRuntime : 'node') | ||
| response.headers.set('x-hello-from-middleware-res', 'hello') | ||
|
|
||
| response.headers.set('x-next-url-pathname', request.nextUrl.pathname) | ||
|
|
||
| return response | ||
| } | ||
| } | ||
|
|
||
| export const config = { | ||
| runtime: 'nodejs', | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,7 @@ import { | |
| } from '../utils/fixture.js' | ||
| import { generateRandomObjectID, startMockBlobStore } from '../utils/helpers.js' | ||
| import { LocalServer } from '../utils/local-server.js' | ||
| import { hasNodeMiddlewareSupport } from '../utils/next-version-helpers.mjs' | ||
| import { hasNodeMiddlewareSupport, nextVersionSatisfies } from '../utils/next-version-helpers.mjs' | ||
|
|
||
| beforeEach<FixtureTestContext>(async (ctx) => { | ||
| // set for each test a new deployID and siteID | ||
|
|
@@ -693,6 +693,17 @@ for (const { | |
| expect(bodyFr.requestUrlPathname).toBe('/fr/json') | ||
| expect(bodyFr.nextUrlPathname).toBe('/json') | ||
| expect(bodyFr.nextUrlLocale).toBe('fr') | ||
|
|
||
| const responseData = await invokeEdgeFunction(ctx, { | ||
| functions: [edgeFunctionNameRoot], | ||
| origin, | ||
| url: `/_next/data/build_id/en/dynamic/test.json?slug=test`, | ||
| }) | ||
|
|
||
| expect( | ||
| responseData.headers.get('x-next-url-pathname'), | ||
| 'nextUrl.pathname should not be normalized due to skipMiddlewareUrlNormalize', | ||
| ).toEqual('/_next/data/build_id/en/dynamic/test.json') | ||
|
Comment on lines
+696
to
+706
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. uff, we actually didn't have any assertion that |
||
| }) | ||
| }) | ||
|
|
||
|
|
@@ -719,6 +730,37 @@ for (const { | |
| ) | ||
| }) | ||
| }) | ||
|
|
||
| describe('Proxy specific', () => { | ||
| test.skipIf(!nextVersionSatisfies('>=16.0.0-alpha.0'))<FixtureTestContext>( | ||
| 'skipProxyUrlNormalize in proxy.ts is supported', | ||
| async (ctx) => { | ||
| await createFixture('proxy-i18n-skip-normalize', ctx) | ||
| await runPlugin(ctx) | ||
| const origin = await LocalServer.run(async (req, res) => { | ||
| res.write( | ||
| JSON.stringify({ | ||
| url: req.url, | ||
| headers: req.headers, | ||
| }), | ||
| ) | ||
| res.end() | ||
| }) | ||
| ctx.cleanup?.push(() => origin.stop()) | ||
|
|
||
| const responseData = await invokeEdgeFunction(ctx, { | ||
| functions: [edgeFunctionNameRoot], | ||
| origin, | ||
| url: `/_next/data/build_id/en/dynamic/test.json`, | ||
| }) | ||
|
|
||
| expect( | ||
| responseData.headers.get('x-next-url-pathname'), | ||
| 'nextUrl.pathname should not be normalized due to skipProxyUrlNormalize', | ||
| ).toEqual('/_next/data/build_id/en/dynamic/test.json') | ||
| }, | ||
| ) | ||
| }) | ||
| } | ||
| }) | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like Proxy will be Node.js only (tho it's not as of now), so I do add this explicitly here in hope the test setup won't break when Next.js ships the change to make Proxy Node.js only. If that change end up not shipping, I'll adjust the setup to run in both Edge and Node.js runtimes as we do for most of our middleware fixtures