UNPKG

azion

Version:

Azion Packages for Edge Computing.

63 lines (62 loc) 2.15 kB
const s = (n) => { const e = new URL(n).pathname, t = e.endsWith("/") ? e.slice(0, -1) : e, o = /\.[^.]+$/; let a; return t === "" ? a = new URL("index.html", "file:///") : o.test(t) ? a = new URL(t.slice(1), "file:///") : a = new URL(`${t.slice(1)}/index.html`, "file:///"), fetch(a); }, c = (n) => { const e = new URL(n).pathname; let t; return /\.[^.]+$/.test(e) ? t = new URL(e.slice(1), "file:///") : t = new URL("index.html", "file:///"), fetch(t); }, i = async (n) => { const e = new Headers(n.headers), t = new URL(n.url); let o = null; if (["POST", "PUT", "PATCH"].includes(n.method)) try { o = await n.clone().text(); } catch { o = "Unable to read body"; } const a = e.get("cookie") ? Object.fromEntries( e.get("cookie").split(";").map((r) => r.trim().split("=")) ) : {}; return { timestamp: (/* @__PURE__ */ new Date()).toISOString(), metadata: n.metadata, method: n.method, url: { full: n.url, protocol: t.protocol, hostname: t.hostname, path: t.pathname, query: Object.fromEntries(t.searchParams) }, headers: Object.fromEntries(e.entries()), cookies: a, body: o, client: { ip: e.get("x-forwarded-for") || "Unknown", userAgent: e.get("user-agent") || "Unknown" }, referer: e.get("referer") || "Unknown", origin: e.get("origin") || "Unknown", cacheControl: e.get("cache-control") || "Unknown", pragma: e.get("pragma") || "Unknown", contentType: e.get("content-type") || "Unknown", contentLength: e.get("content-length") || "Unknown", acceptLanguage: e.get("accept-language") || "Unknown", acceptEncoding: e.get("accept-encoding") || "Unknown", priority: e.get("priority") || "Unknown", host: e.get("host") || "Unknown", authorization: e.has("authorization") ? "Present" : "Not Present" }; }, g = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ __proto__: null, mountMPA: s, mountSPA: c, parseRequest: i }, Symbol.toStringTag, { value: "Module" })); export { g as e, s as mountMPA, c as mountSPA, i as parseRequest };