-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.ts
42 lines (36 loc) · 1.04 KB
/
utils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
function stripHTTPandHTTPS(url: string) {
return url.replace('http://', '').replace('https://', '');
}
function stripTrailingSlash(url: string) {
return url.replace(/\/$/, '');
}
function setHTTP(url: string) {
return `http://${url}`;
}
function setHTTPS(url: string) {
return `https://${url}`;
}
function splitListandSelectFirst(list: string) {
if (list.indexOf(',') === -1) return list;
return list.split(',')[0];
}
/**
* Get the Domain of the Coolify URL from the coolify runtime environment
*
* Requires the COOLIFY_FQDN environment variable to be set as per the coolify docs:
*
* @see https://coolify.io/docs/knowledge-base/environment-variables#predefined-variables
*/
export const getCoolifyURL = (returnHttps?: boolean) => {
const urlList = process.env.COOLIFY_FQDN;
if (!urlList) {
return undefined;
}
const url = splitListandSelectFirst(urlList);
const strippedUrl = stripTrailingSlash(stripHTTPandHTTPS(url));
if (returnHttps) {
return setHTTPS(strippedUrl);
}
return setHTTP(strippedUrl);
};
export default getCoolifyURL;