full site update
This commit is contained in:
30
node_modules/astro/dist/vite-plugin-astro-server/trailing-slash.js
generated
vendored
Normal file
30
node_modules/astro/dist/vite-plugin-astro-server/trailing-slash.js
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
import { collapseDuplicateTrailingSlashes, hasFileExtension } from "@astrojs/internal-helpers/path";
|
||||
import { trailingSlashMismatchTemplate } from "../template/4xx.js";
|
||||
import { writeHtmlResponse, writeRedirectResponse } from "./response.js";
|
||||
function trailingSlashMiddleware(settings) {
|
||||
const { trailingSlash } = settings.config;
|
||||
return function devTrailingSlash(req, res, next) {
|
||||
const url = new URL(`http://localhost${req.url}`);
|
||||
let pathname;
|
||||
try {
|
||||
pathname = decodeURI(url.pathname);
|
||||
} catch (e) {
|
||||
return next(e);
|
||||
}
|
||||
if (pathname.startsWith("/_") || pathname.startsWith("/@")) {
|
||||
return next();
|
||||
}
|
||||
const destination = collapseDuplicateTrailingSlashes(pathname, true);
|
||||
if (pathname && destination !== pathname) {
|
||||
return writeRedirectResponse(res, 301, `${destination}${url.search}`);
|
||||
}
|
||||
if (trailingSlash === "never" && pathname.endsWith("/") && pathname !== "/" || trailingSlash === "always" && !pathname.endsWith("/") && !hasFileExtension(pathname)) {
|
||||
const html = trailingSlashMismatchTemplate(pathname, trailingSlash);
|
||||
return writeHtmlResponse(res, 404, html);
|
||||
}
|
||||
return next();
|
||||
};
|
||||
}
|
||||
export {
|
||||
trailingSlashMiddleware
|
||||
};
|
Reference in New Issue
Block a user