fix: layered middleware not working for index page (#407)
This commit fixes layered middleware not being invoked for the the index page of the layer. For example: routes/api/_middleware.ts was not being invoked for /api, only /api/foobar
This commit is contained in:
@@ -690,7 +690,10 @@ function serializeCSPDirectives(csp: ContentSecurityPolicyDirectives): string {
|
||||
|
||||
export function middlewarePathToPattern(baseRoute: string) {
|
||||
baseRoute = baseRoute.slice(0, -"_middleware".length);
|
||||
const pattern = pathToPattern(baseRoute);
|
||||
const compiledPattern = new URLPattern({ pathname: `${pattern}*` });
|
||||
let pattern = pathToPattern(baseRoute);
|
||||
if (pattern.endsWith("/")) {
|
||||
pattern = pattern.slice(0, -1) + "{/*}?";
|
||||
}
|
||||
const compiledPattern = new URLPattern({ pathname: pattern });
|
||||
return { pattern, compiledPattern };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user