fix: middleware logic Routing Forms (#10412)

* Match /apps/routing_forms

* Next.js config.matcher doesnt support spread operator
pull/10413/head
Hariom Balhara 2023-07-27 16:48:17 +05:30 committed by GitHub
parent 98a156311d
commit 48b79b618f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 6 deletions

View File

@ -79,22 +79,22 @@ const routingForms = {
handle: (url: URL) => { handle: (url: URL) => {
// Next.config.js Redirects don't handle Client Side navigations and we need that. // Next.config.js Redirects don't handle Client Side navigations and we need that.
// So, we add the rewrite here instead. // So, we add the rewrite here instead.
if (url.pathname.startsWith("/routing-forms/")) { if (url.pathname.startsWith("/routing-forms")) {
url.pathname = url.pathname.replace(/^\/routing-forms\//, "/apps/routing-forms/"); url.pathname = url.pathname.replace(/^\/routing-forms($|\/)/, "/apps/routing-forms/");
return NextResponse.rewrite(url); return NextResponse.rewrite(url);
} }
// Don't 404 old routing_forms links // Don't 404 old routing_forms links
if (url.pathname.startsWith("/apps/routing_forms")) { if (url.pathname.startsWith("/apps/routing_forms")) {
url.pathname = url.pathname.replace(/^\/apps\/routing_forms\//, "/apps/routing-forms/"); url.pathname = url.pathname.replace(/^\/apps\/routing_forms($|\/)/, "/apps/routing-forms/");
return NextResponse.rewrite(url); return NextResponse.rewrite(url);
} }
}, },
// Matcher paths that are required by the handle function to work
paths: ["/apps/routing_forms/:path*", "/routing-forms/:path*"],
}; };
export const config = { export const config = {
// Next.js Doesn't support spread operator in config matcher, so, we must list all paths explicitly here.
// https://github.com/vercel/next.js/discussions/42458
matcher: [ matcher: [
"/((?!_next|.*avatar.png$|favicon.ico$).*)", "/((?!_next|.*avatar.png$|favicon.ico$).*)",
"/api/collect-events/:path*", "/api/collect-events/:path*",
@ -102,7 +102,12 @@ export const config = {
"/:path*/embed", "/:path*/embed",
"/api/trpc/:path*", "/api/trpc/:path*",
"/auth/login", "/auth/login",
...routingForms.paths,
/**
* Paths required by routingForms.handle
*/
"/apps/routing_forms/:path*",
"/routing-forms/:path*",
], ],
}; };