Unverified Commit 8303c564 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Pass through original matcher source in manifest (#46753)

This ensures we pass through the original matcher source in the
middleware manifest for posterity.
parent 25efdfad
......@@ -30,6 +30,7 @@ export interface MiddlewareMatcher {
locale?: false
has?: RouteHas[]
missing?: RouteHas[]
originalSource: string
}
export interface PageStaticInfo {
......@@ -197,6 +198,7 @@ export function getMiddlewareMatchers(
return {
...rest,
regexp: parsedPage.regexStr,
originalSource: source,
}
})
}
......
......@@ -416,7 +416,7 @@ export async function createEntrypoints(params: CreateEntrypointsParams) {
if (isMiddlewareFile(page)) {
middlewareMatchers = staticInfo.middleware?.matchers ?? [
{ regexp: '.*' },
{ regexp: '.*', originalSource: '/:path*' },
]
}
......
......@@ -171,14 +171,20 @@ function getCreateAssets(params: {
continue
}
const { namedRegex } = getNamedMiddlewareRegex(
metadata.edgeSSR?.isAppDir ? normalizeAppPath(page) : page,
{
catchAll: !metadata.edgeSSR && !metadata.edgeApiFunction,
}
)
const matcherSource = metadata.edgeSSR?.isAppDir
? normalizeAppPath(page)
: page
const catchAll = !metadata.edgeSSR && !metadata.edgeApiFunction
const { namedRegex } = getNamedMiddlewareRegex(matcherSource, {
catchAll,
})
const matchers = metadata?.edgeMiddleware?.matchers ?? [
{ regexp: namedRegex },
{
regexp: namedRegex,
originalSource: page === '/' && catchAll ? '/:path*' : matcherSource,
},
]
const edgeFunctionDefinition: EdgeFunctionDefinition = {
......
......@@ -497,7 +497,7 @@ export default class DevServer extends Server {
}
this.actualMiddlewareFile = rootFile
middlewareMatchers = staticInfo.middleware?.matchers || [
{ regexp: '.*' },
{ regexp: '.*', originalSource: '/:path*' },
]
continue
}
......
......@@ -88,7 +88,7 @@ export async function makeResolver(
if (middleware.files?.length) {
const matchers = middleware.matcher
? getMiddlewareMatchers(middleware.matcher, nextConfig)
: [{ regexp: '.*' }]
: [{ regexp: '.*', originalSource: '/:path*' }]
// @ts-expect-error
devServer.middleware = {
page: '/',
......
......@@ -61,6 +61,7 @@ createNextDescribe(
expect(manifest.functions['/(group)/group/page'].matchers).toEqual([
{
regexp: '^/group$',
originalSource: '/group',
},
])
})
......
......@@ -109,7 +109,7 @@ describe('Middleware Runtime', () => {
`/_next/static/${next.buildId}/_devMiddlewareManifest.json`
)
const matchers = await res.json()
expect(matchers).toEqual([{ regexp: '.*' }])
expect(matchers).toEqual([{ regexp: '.*', originalSource: '/:path*' }])
})
}
......@@ -131,7 +131,7 @@ describe('Middleware Runtime', () => {
]),
name: 'middleware',
page: '/',
matchers: [{ regexp: '^/.*$' }],
matchers: [{ regexp: '^/.*$', originalSource: '/:path*' }],
wasm: [],
assets: [],
regions: 'auto',
......
......@@ -115,7 +115,7 @@ describe('Middleware Runtime trailing slash', () => {
name: 'middleware',
env: [],
page: '/',
matchers: [{ regexp: '^/.*$' }],
matchers: [{ regexp: '^/.*$', originalSource: '/:path*' }],
wasm: [],
assets: [],
},
......
......@@ -194,7 +194,9 @@ describe('Switchable runtime', () => {
],
name: 'pages/api/hello',
page: '/api/hello',
matchers: [{ regexp: '^/api/hello$' }],
matchers: [
{ regexp: '^/api/hello$', originalSource: '/api/hello' },
],
wasm: [],
},
'/api/edge': {
......@@ -205,7 +207,9 @@ describe('Switchable runtime', () => {
],
name: 'pages/api/edge',
page: '/api/edge',
matchers: [{ regexp: '^/api/edge$' }],
matchers: [
{ regexp: '^/api/edge$', originalSource: '/api/edge' },
],
wasm: [],
},
},
......@@ -626,7 +630,9 @@ describe('Switchable runtime', () => {
],
name: 'pages/api/hello',
page: '/api/hello',
matchers: [{ regexp: '^/api/hello$' }],
matchers: [
{ regexp: '^/api/hello$', originalSource: '/api/hello' },
],
wasm: [],
},
'/api/edge': {
......@@ -637,7 +643,9 @@ describe('Switchable runtime', () => {
],
name: 'pages/api/edge',
page: '/api/edge',
matchers: [{ regexp: '^/api/edge$' }],
matchers: [
{ regexp: '^/api/edge$', originalSource: '/api/edge' },
],
wasm: [],
},
},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment