astro-ghostcms/.pnpm-store/v3/files/d9/91dbf0498ae2f4e77a363d494bf...

34 lines
1.0 KiB
Plaintext

import { bold } from "kleur/colors";
async function renderEndpoint(mod, context, ssr, logger) {
const { request, url } = context;
const method = request.method.toUpperCase();
const handler = mod[method] ?? mod["ALL"];
if (!ssr && ssr === false && method !== "GET") {
logger.warn(
"router",
`${url.pathname} ${bold(
method
)} requests are not available for a static site. Update your config to \`output: 'server'\` or \`output: 'hybrid'\` to enable.`
);
}
if (typeof handler !== "function") {
logger.warn(
"router",
`No API Route handler exists for the method "${method}" for the route ${url.pathname}.
Found handlers: ${Object.keys(mod).map((exp) => JSON.stringify(exp)).join(", ")}
` + ("all" in mod ? `One of the exported handlers is "all" (lowercase), did you mean to export 'ALL'?
` : "")
);
return new Response(null, {
status: 404,
headers: {
"X-Astro-Response": "Not-Found"
}
});
}
return handler.call(mod, context);
}
export {
renderEndpoint
};