feat: init
This commit is contained in:
53
node_modules/nitropack/dist/presets/netlify/runtime/netlify.mjs
generated
vendored
Normal file
53
node_modules/nitropack/dist/presets/netlify/runtime/netlify.mjs
generated
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
import "#nitro-internal-pollyfills";
|
||||
import { useNitroApp } from "nitropack/runtime";
|
||||
import {
|
||||
getRouteRulesForPath,
|
||||
joinHeaders,
|
||||
normalizeCookieHeader
|
||||
} from "nitropack/runtime/internal";
|
||||
const nitroApp = useNitroApp();
|
||||
const handler = async (req) => {
|
||||
const url = new URL(req.url);
|
||||
const relativeUrl = `${url.pathname}${url.search}`;
|
||||
const r = await nitroApp.localCall({
|
||||
url: relativeUrl,
|
||||
headers: req.headers,
|
||||
method: req.method,
|
||||
body: req.body
|
||||
});
|
||||
const headers = normalizeResponseHeaders({
|
||||
...getCacheHeaders(url.pathname),
|
||||
...r.headers
|
||||
});
|
||||
return new Response(r.body, {
|
||||
status: r.status,
|
||||
headers
|
||||
});
|
||||
};
|
||||
export default handler;
|
||||
const ONE_YEAR_IN_SECONDS = 365 * 24 * 60 * 60;
|
||||
function normalizeResponseHeaders(headers) {
|
||||
const outgoingHeaders = new Headers();
|
||||
for (const [name, header] of Object.entries(headers)) {
|
||||
if (name === "set-cookie") {
|
||||
for (const cookie of normalizeCookieHeader(header)) {
|
||||
outgoingHeaders.append("set-cookie", cookie);
|
||||
}
|
||||
} else if (header !== void 0) {
|
||||
outgoingHeaders.set(name, joinHeaders(header));
|
||||
}
|
||||
}
|
||||
return outgoingHeaders;
|
||||
}
|
||||
function getCacheHeaders(url) {
|
||||
const { isr } = getRouteRulesForPath(url);
|
||||
if (isr) {
|
||||
const maxAge = typeof isr === "number" ? isr : ONE_YEAR_IN_SECONDS;
|
||||
const revalidateDirective = typeof isr === "number" ? `stale-while-revalidate=${ONE_YEAR_IN_SECONDS}` : "must-revalidate";
|
||||
return {
|
||||
"Cache-Control": "public, max-age=0, must-revalidate",
|
||||
"Netlify-CDN-Cache-Control": `public, max-age=${maxAge}, ${revalidateDirective}, durable`
|
||||
};
|
||||
}
|
||||
return {};
|
||||
}
|
||||
Reference in New Issue
Block a user