🔗 Add support for shorter urls (#750)

This commit is contained in:
Luke Vella 2023-07-14 14:27:11 +01:00 committed by GitHub
parent 30a1136529
commit 2e5468ed65
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 5 deletions

View file

@ -6,10 +6,17 @@ const getVercelUrl = () => {
: null;
};
export function absoluteUrl(path = "") {
export function absoluteUrl(subpath = "") {
const baseUrl =
process.env.NEXT_PUBLIC_BASE_URL ??
getVercelUrl() ??
`http://localhost:${port}`;
return `${baseUrl}${path}`;
const url = new URL(subpath, baseUrl);
return url.href;
}
export function shortUrl(subpath = "") {
const baseUrl = process.env.NEXT_PUBLIC_SHORT_BASE_URL ?? absoluteUrl();
const url = new URL(subpath, baseUrl);
return url.href;
}