mirror of
https://github.com/lukevella/rallly.git
synced 2025-05-13 17:06:48 +02:00
First public commit
This commit is contained in:
commit
e05cd62e53
228 changed files with 17717 additions and 0 deletions
36
utils/absolute-url.ts
Normal file
36
utils/absolute-url.ts
Normal 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;
|
Loading…
Add table
Add a link
Reference in a new issue