mirror of
https://github.com/lukevella/rallly.git
synced 2025-05-23 05:46:20 +02:00
30 lines
744 B
TypeScript
30 lines
744 B
TypeScript
const port = process.env.PORT || 3000;
|
|
|
|
const getVercelUrl = () => {
|
|
return process.env.NEXT_PUBLIC_VERCEL_URL
|
|
? `https://${process.env.NEXT_PUBLIC_VERCEL_URL}`
|
|
: null;
|
|
};
|
|
|
|
function joinPath(baseUrl: string, subpath = "") {
|
|
if (subpath) {
|
|
const url = new URL(subpath, baseUrl);
|
|
return url.href;
|
|
}
|
|
|
|
return baseUrl;
|
|
}
|
|
|
|
export function absoluteUrl(subpath = "", query?: Record<string, string>) {
|
|
const queryString = query
|
|
? `?${Object.entries(query)
|
|
.map(([key, value]) => `${key}=${encodeURIComponent(value)}`)
|
|
.join("&")}`
|
|
: "";
|
|
const baseUrl =
|
|
process.env.NEXT_PUBLIC_BASE_URL ??
|
|
getVercelUrl() ??
|
|
`http://localhost:${port}`;
|
|
|
|
return joinPath(baseUrl, subpath) + queryString;
|
|
}
|