perf: optimize production assets and proxy-aware URLs

This commit is contained in:
2026-07-12 17:27:02 +05:30
parent 935b3103dd
commit 6dfef7da3c
58 changed files with 118 additions and 90 deletions
+5 -2
View File
@@ -178,9 +178,12 @@ export function createCorsPreflightResponse(
export function resolveRequestUrl(req: Request, trustProxy?: boolean): URL {
const url = new URL(req.url);
if (!trustProxy) return url;
const proto = req.headers.get("x-forwarded-proto");
const forwarded = req.headers.get("forwarded")?.split(",")[0] ?? "";
const forwardedProto = /(?:^|;)\s*proto=(?:"([^"]+)"|([^;\s]+))/i.exec(forwarded);
const forwardedHost = /(?:^|;)\s*host=(?:"([^"]+)"|([^;\s]+))/i.exec(forwarded);
const proto = req.headers.get("x-forwarded-proto") ?? forwardedProto?.[1] ?? forwardedProto?.[2];
if (proto) url.protocol = (proto.split(",")[0] ?? "").trim() + ":";
const host = req.headers.get("x-forwarded-host");
const host = req.headers.get("x-forwarded-host") ?? forwardedHost?.[1] ?? forwardedHost?.[2];
if (host) {
const h = (host.split(",")[0] ?? "").trim();
url.host = h;