Skip to content

Commit

Permalink
[next] Populate middlewareRawSrc using middleware originalSource (ver…
Browse files Browse the repository at this point in the history
…cel#9602)

Next.js will pass the original middleware matching routes through to the middleware manifest once vercel/next.js#46753 lands. This PR will take those original values and put them in the middleware route `middlewareRawSrc` property.

NOTE: The tests will need to be updated once the Next.js version is updated in the fixtures.
  • Loading branch information
Chris Barber authored Mar 7, 2023
1 parent 57e8ec1 commit 38244c8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/next/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2362,6 +2362,7 @@ interface EdgeFunctionMatcher {
regexp: string;
has?: HasField;
missing?: HasField;
originalSource?: string;
}

export async function getMiddlewareBundle({
Expand Down Expand Up @@ -2579,6 +2580,9 @@ export async function getMiddlewareBundle({
};

route.middlewarePath = shortPath;
route.middlewareRawSrc = matcher.originalSource
? [matcher.originalSource]
: [];
if (isCorrectMiddlewareOrder) {
route.override = true;
}
Expand Down Expand Up @@ -2701,6 +2705,7 @@ function getRouteMatchers(
return info.matchers.map(matcher => {
const m: EdgeFunctionMatcher = {
regexp: getRegexp(matcher.regexp),
originalSource: matcher.originalSource,
};
if (matcher.has) {
m.has = normalizeHas(matcher.has);
Expand Down
6 changes: 6 additions & 0 deletions packages/next/test/unit/middleware-routes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ describe('middleware routes', () => {
{
continue: true,
middlewarePath: 'middleware',
middlewareRawSrc: [],
missing: [
{
key: 'x-prerender-revalidate',
Expand Down Expand Up @@ -51,6 +52,7 @@ describe('middleware routes', () => {
{
continue: true,
middlewarePath: 'middleware',
middlewareRawSrc: [],
missing: [
{
key: 'x-prerender-revalidate',
Expand Down Expand Up @@ -94,6 +96,7 @@ describe('middleware routes', () => {
{
continue: true,
middlewarePath: 'middleware',
middlewareRawSrc: [],
missing: [
{
key: 'x-prerender-revalidate',
Expand All @@ -114,6 +117,7 @@ describe('middleware routes', () => {
},
],
middlewarePath: 'middleware',
middlewareRawSrc: [],
missing: [
{
key: 'x-prerender-revalidate',
Expand Down Expand Up @@ -161,6 +165,7 @@ describe('middleware routes', () => {
},
],
middlewarePath: 'middleware',
middlewareRawSrc: [],
missing: [
{
key: 'x-prerender-revalidate',
Expand Down Expand Up @@ -193,6 +198,7 @@ describe('middleware routes', () => {
{
continue: true,
middlewarePath: 'middleware',
middlewareRawSrc: [],
missing: [
{
key: 'x-prerender-revalidate',
Expand Down

0 comments on commit 38244c8

Please sign in to comment.