-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathurls.ts
More file actions
68 lines (55 loc) · 1.75 KB
/
urls.ts
File metadata and controls
68 lines (55 loc) · 1.75 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import axios from "axios";
import { getAuthUrl, getDb } from "../store/db";
// Console API Server
export const getConsoleServer = (port?: number) => {
const devMode = process.env.NODE_ENV === "development";
const host = devMode
? "http://0.0.0.0"
: "https://console.bless.network";
return `${host}:${port ? port : devMode ? 3005 : 443}`;
};
export const getGatewayUrl = (): string => {
const authUrl = getAuthUrl();
const protocol = authUrl.port === 443 ? "https" : "http";
return authUrl
? authUrl.port === 443 || authUrl.port === 80
? `${protocol}://${authUrl.url}`
: `${protocol}://${authUrl.url}:${authUrl.port}`
: getConsoleServer();
};
export const getGatewayDeploymentUrl = (
subdomain: string | null,
domainMappings: { domain: string }[]
): string | null => {
let domain = null;
const gatewayVersion = getDb().get("config.apiVersion").value();
if (gatewayVersion === 1) {
const gatewayUrl = getAuthUrl();
if (domainMappings.length > 0) {
domain = domainMappings[0].domain;
} else {
domain = `${subdomain}.${gatewayUrl.url}`;
}
} else {
if (domainMappings.length > 0) {
domain = domainMappings[0].domain;
}
}
return domain;
};
export async function validateGatewayVersion(gatewayUrl: string) {
let version = 0;
try {
const response = await axios.get(`${gatewayUrl}/version`);
if (!!response.data.apiVersion) {
version = response.data.apiVersion;
}
} catch (error) {}
return version;
}
// WASI Repo Server
export const getWASMRepoServer = (port?: number) => {
const devMode = process.env.NODE_ENV === "development";
const host = devMode ? "http://0.0.0.0" : "https://wasi.bls.dev";
return `${host}:${port ? port : devMode ? 3006 : 443}`;
};