astro
Version:
Astro is a modern site builder with web best practices, performance, and DX front-of-mind.
43 lines (42 loc) • 1.05 kB
JavaScript
import notFoundTemplate from "../../template/4xx.js";
import { DEFAULT_404_COMPONENT } from "../constants.js";
const DEFAULT_404_ROUTE = {
component: DEFAULT_404_COMPONENT,
generate: () => "",
params: [],
pattern: /\/404/,
prerender: false,
pathname: "/404",
segments: [[{ content: "404", dynamic: false, spread: false }]],
type: "page",
route: "/404",
fallbackRoutes: [],
isIndex: false,
origin: "internal"
};
function ensure404Route(manifest) {
if (!manifest.routes.some((route) => route.route === "/404")) {
manifest.routes.push(DEFAULT_404_ROUTE);
}
return manifest;
}
async function default404Page({ pathname }) {
return new Response(
notFoundTemplate({
statusCode: 404,
title: "Not found",
tabTitle: "404: Not Found",
pathname
}),
{ status: 404, headers: { "Content-Type": "text/html" } }
);
}
default404Page.isAstroComponentFactory = true;
const default404Instance = {
default: default404Page
};
export {
DEFAULT_404_ROUTE,
default404Instance,
ensure404Route
};