Remove trailing slash on urls
This commit is contained in:
parent
7dd91f5847
commit
90266abc91
|
@ -11,6 +11,7 @@ export default defineConfig({
|
||||||
srcDir: "./src",
|
srcDir: "./src",
|
||||||
publicDir: "./public",
|
publicDir: "./public",
|
||||||
outDir: "./dist",
|
outDir: "./dist",
|
||||||
|
trailingSlash: "never",
|
||||||
adapter: node({
|
adapter: node({
|
||||||
mode: "standalone",
|
mode: "standalone",
|
||||||
}),
|
}),
|
||||||
|
|
|
@ -7,11 +7,13 @@ import { actionsHandlingMiddleware } from "src/middleware/actionsHandling";
|
||||||
import { requestTrackingMiddleware } from "src/middleware/requestTracking";
|
import { requestTrackingMiddleware } from "src/middleware/requestTracking";
|
||||||
import { pageCachingMiddleware } from "src/middleware/pageCaching";
|
import { pageCachingMiddleware } from "src/middleware/pageCaching";
|
||||||
import { setAstroLocalsMiddleware } from "src/middleware/setAstroLocals";
|
import { setAstroLocalsMiddleware } from "src/middleware/setAstroLocals";
|
||||||
|
import { removeTrailingSlashMiddleware } from "src/middleware/removeTrailingSlash";
|
||||||
|
|
||||||
export const onRequest = sequence(
|
export const onRequest = sequence(
|
||||||
// Possible redirect
|
// Possible redirect
|
||||||
actionsHandlingMiddleware,
|
actionsHandlingMiddleware,
|
||||||
localeNegotiationMiddleware,
|
localeNegotiationMiddleware,
|
||||||
|
removeTrailingSlashMiddleware,
|
||||||
|
|
||||||
addCommonHeadersMiddleware,
|
addCommonHeadersMiddleware,
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
import { defineMiddleware } from "astro:middleware";
|
||||||
|
import { redirect } from "src/middleware/utils";
|
||||||
|
|
||||||
|
export const removeTrailingSlashMiddleware = defineMiddleware(({ url }, next) => {
|
||||||
|
if (url.pathname.endsWith("/")) {
|
||||||
|
url.pathname = url.pathname.substring(0, url.pathname.length - 1);
|
||||||
|
return redirect(url.toString());
|
||||||
|
}
|
||||||
|
return next();
|
||||||
|
});
|
Loading…
Reference in New Issue