refactor: added support for base url using a shared function

This commit is contained in:
2023-01-11 12:29:37 +01:00
parent 64617fffcf
commit 2dfe47b16e
11 changed files with 42 additions and 24 deletions
+16
View File
@@ -28,3 +28,19 @@ function sortByKey<T, K>(compareFn: (a: K, b: K) => number, items: T[], keyFn: (
sortedList.sort((a, b) => order * compareFn(keyFn(a), keyFn(b)))
return sortedList
}
//
// Base Url
//
export function prependBaseUrl(route: string) {
// @ts-ignore
if (typeof window === 'undefined') {
// NodeJS
return process.env.BASE_URL + (route.startsWith('/') ? route.substring(1) : route)
} else {
// Browser
// @ts-ignore
return import.meta.env.BASE_URL + (route.startsWith('/') ? route.substring(1) : route)
}
}