App directory #4

This commit is contained in:
Darren Clarke 2023-06-28 12:55:24 +00:00 committed by GitHub
parent 69706053c6
commit 4d743c5e67
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
86 changed files with 223 additions and 107 deletions

View file

@ -1,35 +0,0 @@
import { IncomingMessage } from "node:http";
function absoluteUrl(
req?: IncomingMessage,
localhostAddress = "localhost:3000"
) {
let host =
(req?.headers ? req.headers.host : window.location.host) ||
localhostAddress;
let protocol = /^localhost(:\d+)?$/.test(host) ? "http:" : "https:";
if (
req &&
req.headers["x-forwarded-host"] &&
typeof req.headers["x-forwarded-host"] === "string"
) {
host = req.headers["x-forwarded-host"];
}
if (
req &&
req.headers["x-forwarded-proto"] &&
typeof req.headers["x-forwarded-proto"] === "string"
) {
protocol = `${req.headers["x-forwarded-proto"]}:`;
}
return {
protocol,
host,
origin: protocol + "//" + host,
};
}
export default absoluteUrl;