First public commit

This commit is contained in:
Luke Vella 2022-04-12 07:14:28 +01:00
commit e05cd62e53
228 changed files with 17717 additions and 0 deletions

36
utils/absolute-url.ts Normal file
View file

@ -0,0 +1,36 @@
// Source: https://github.com/jakeburden/next-absolute-url/blob/1d96d1d2a2a2308db60ce53a130b5d47aab3ee25/index.ts
import { IncomingMessage } from "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;