Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
@@ -3,6 +3,7 @@ export type DomainRoutingEnv = Record<string, string | undefined> & {
|
||||
WEB_APP_HOST?: string;
|
||||
ADMIN_APP_HOST?: string;
|
||||
API_HOST?: string;
|
||||
PORTAL_APP_HOST?: string;
|
||||
APP_PROTOCOL?: string;
|
||||
NODE_ENV?: string;
|
||||
};
|
||||
@@ -12,6 +13,7 @@ export type DomainRoutingConfig = {
|
||||
webAppHost: string;
|
||||
adminAppHost: string;
|
||||
apiHost: string;
|
||||
portalAppHost: string;
|
||||
protocol: "http" | "https";
|
||||
};
|
||||
|
||||
@@ -19,17 +21,21 @@ const LOCAL_BASE_DOMAIN = "localhost";
|
||||
const LOCAL_WEB_APP_HOST = "app.localhost";
|
||||
const LOCAL_ADMIN_APP_HOST = "admin.localhost";
|
||||
const LOCAL_API_HOST = "api.localhost";
|
||||
const LOCAL_PORTAL_APP_HOST = "portal.localhost";
|
||||
|
||||
export function getDomainRoutingConfig(env: DomainRoutingEnv = process.env): DomainRoutingConfig {
|
||||
const appBaseDomain = normalizeHost(env.APP_BASE_DOMAIN) ?? LOCAL_BASE_DOMAIN;
|
||||
const rawBaseDomain = normalizeHost(env.APP_BASE_DOMAIN) ?? LOCAL_BASE_DOMAIN;
|
||||
const protocol = normalizeProtocol(env.APP_PROTOCOL) ?? (isLocalHost(rawBaseDomain) || env.NODE_ENV === "development" ? "http" : "https");
|
||||
const appBaseDomain = normalizeHostForProtocol(rawBaseDomain, protocol) ?? rawBaseDomain;
|
||||
const derivedHosts = getDerivedHosts(appBaseDomain);
|
||||
|
||||
return {
|
||||
appBaseDomain,
|
||||
webAppHost: normalizeHost(env.WEB_APP_HOST) ?? derivedHosts.webAppHost,
|
||||
adminAppHost: normalizeHost(env.ADMIN_APP_HOST) ?? derivedHosts.adminAppHost,
|
||||
apiHost: normalizeHost(env.API_HOST) ?? derivedHosts.apiHost,
|
||||
protocol: normalizeProtocol(env.APP_PROTOCOL) ?? (isLocalHost(appBaseDomain) || env.NODE_ENV === "development" ? "http" : "https"),
|
||||
webAppHost: normalizeHostForProtocol(env.WEB_APP_HOST, protocol) ?? derivedHosts.webAppHost,
|
||||
adminAppHost: normalizeHostForProtocol(env.ADMIN_APP_HOST, protocol) ?? derivedHosts.adminAppHost,
|
||||
apiHost: normalizeHostForProtocol(env.API_HOST, protocol) ?? derivedHosts.apiHost,
|
||||
portalAppHost: normalizeHostForProtocol(env.PORTAL_APP_HOST, protocol) ?? derivedHosts.portalAppHost,
|
||||
protocol,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -39,9 +45,29 @@ export function normalizeHost(value: string | undefined): string | undefined {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const withProtocol = /^[a-z][a-z\d+\-.]*:\/\//i.test(trimmed) ? trimmed : `http://${trimmed}`;
|
||||
const url = new URL(withProtocol);
|
||||
return url.host.toLowerCase();
|
||||
try {
|
||||
const withProtocol = /^[a-z][a-z\d+\-.]*:\/\//i.test(trimmed) ? trimmed : `http://${trimmed}`;
|
||||
const url = new URL(withProtocol);
|
||||
return url.host.toLowerCase();
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
export function normalizeHostForProtocol(
|
||||
value: string | undefined,
|
||||
protocol: DomainRoutingConfig["protocol"]
|
||||
): string | undefined {
|
||||
const host = normalizeHost(value);
|
||||
if (!host) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
try {
|
||||
return new URL(`${protocol}://${host}`).host.toLowerCase();
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
export function hostMatches(actualHost: string | undefined, expectedHost: string | undefined): boolean {
|
||||
@@ -82,6 +108,7 @@ function getDerivedHosts(baseDomain: string) {
|
||||
webAppHost: withLocalPort(LOCAL_WEB_APP_HOST, baseDomain),
|
||||
adminAppHost: withLocalPort(LOCAL_ADMIN_APP_HOST, baseDomain),
|
||||
apiHost: withLocalPort(LOCAL_API_HOST, baseDomain),
|
||||
portalAppHost: withLocalPort(LOCAL_PORTAL_APP_HOST, baseDomain),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -89,6 +116,7 @@ function getDerivedHosts(baseDomain: string) {
|
||||
webAppHost: withSubdomain("app", baseDomain),
|
||||
adminAppHost: withSubdomain("admin", baseDomain),
|
||||
apiHost: withSubdomain("api", baseDomain),
|
||||
portalAppHost: withSubdomain("portal", baseDomain),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user