Files
Mebbling/lib/http.ts
T

7 lines
362 B
TypeScript

export function externalUrl(request: Request, pathname: string) {
const current = new URL(request.url);
const host = request.headers.get("x-forwarded-host") || request.headers.get("host") || current.host;
const protocol = request.headers.get("x-forwarded-proto") || current.protocol.replace(":", "");
return new URL(pathname, `${protocol}://${host}`);
}