fix: trailingSlash option (#1426)
This commit is contained in:
+10
-1
@@ -403,7 +403,16 @@ export class ServerContext {
|
||||
headers: { location },
|
||||
});
|
||||
} else if (trailingSlashEnabled && !url.pathname.endsWith("/")) {
|
||||
return Response.redirect(url.href + "/", Status.PermanentRedirect);
|
||||
// If the last element of the path has a "." it's a file
|
||||
const isFile = url.pathname.split("/").at(-1)?.includes(".");
|
||||
|
||||
// If the path uses the internal prefix, don't redirect it
|
||||
const isInternal = url.pathname.startsWith(INTERNAL_PREFIX);
|
||||
|
||||
if (!isFile && !isInternal) {
|
||||
url.pathname += "/";
|
||||
return Response.redirect(url, Status.PermanentRedirect);
|
||||
}
|
||||
}
|
||||
|
||||
return await withMiddlewares(req, connInfo, inner);
|
||||
|
||||
Reference in New Issue
Block a user