-
Couldn't load subscription status.
- Fork 92
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
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,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, | ||
| } |
| 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" | ||
| } | ||
| } | ||
| } |
| 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, | ||
| }, | ||
| } | ||
| } |
| 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', | ||
| } | ||
| 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') | ||
| }, | ||
| ) | ||
| }) | ||
| } | ||
| }) | ||
| } | ||
|
|
||
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