mirror of
https://github.com/lukevella/rallly.git
synced 2025-06-28 07:17:14 +02:00
♻️ Update eslint config (#1424)
This commit is contained in:
parent
01396b6129
commit
d55131c2ab
162 changed files with 337 additions and 266 deletions
38
packages/utils/src/absolute-url.ts
Normal file
38
packages/utils/src/absolute-url.ts
Normal file
|
@ -0,0 +1,38 @@
|
|||
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 baseUrl =
|
||||
process.env.NEXT_PUBLIC_BASE_URL ??
|
||||
getVercelUrl() ??
|
||||
`http://localhost:${port}`;
|
||||
|
||||
const url = new URL(subpath, baseUrl);
|
||||
|
||||
Object.entries(query).forEach(([key, value]) => {
|
||||
url.searchParams.set(key, value);
|
||||
});
|
||||
|
||||
const urlString = url.href;
|
||||
|
||||
return urlString.endsWith("/") ? urlString.slice(0, -1) : urlString;
|
||||
}
|
||||
|
||||
export function shortUrl(subpath = "") {
|
||||
const baseUrl = process.env.NEXT_PUBLIC_SHORT_BASE_URL ?? absoluteUrl();
|
||||
return joinPath(baseUrl, subpath);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue