Add X-Forwarded-Proto support

This commit is contained in:
2023-07-01 08:30:28 +08:00
parent f636262cf8
commit 71f5516c2c
4 changed files with 12 additions and 3 deletions

View File

@@ -40,3 +40,9 @@ export function return_json<T = unknown>(data: T, status = 200) {
headers: { "Content-Type": "application/json" },
});
}
export function get_host(req: Request) {
const u = new URL(req.url);
const proto = req.headers.get("X-Forwarded-Proto");
return proto ? `${proto}://${u.host}` : u.origin;
}