feat: init

This commit is contained in:
2026-02-13 22:02:30 +01:00
commit 8f9ff830fb
16711 changed files with 3307340 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
import "#nitro-internal-pollyfills";
import type { Context } from "@netlify/edge-functions";
export default function netlifyEdge(request: Request, _context: Context): Promise<any>;

View File

@@ -0,0 +1,25 @@
import "#nitro-internal-pollyfills";
import { useNitroApp } from "nitropack/runtime";
import { isPublicAssetURL } from "#nitro-internal-virtual/public-assets";
const nitroApp = useNitroApp();
export default async function netlifyEdge(request, _context) {
const url = new URL(request.url);
if (isPublicAssetURL(url.pathname)) {
return;
}
if (!request.headers.has("x-forwarded-proto") && url.protocol === "https:") {
request.headers.set("x-forwarded-proto", "https");
}
let body;
if (request.body) {
body = await request.arrayBuffer();
}
return nitroApp.localFetch(url.pathname + url.search, {
host: url.hostname,
protocol: url.protocol,
headers: request.headers,
method: request.method,
redirect: request.redirect,
body
});
}

View File

@@ -0,0 +1,3 @@
import "#nitro-internal-pollyfills";
declare const handler: (req: Request) => Promise<Response>;
export default handler;

View 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 {};
}