37 lines
1.4 KiB
TypeScript
37 lines
1.4 KiB
TypeScript
// Sites Framework Utilities
|
|
// URL building utilities - do not modify
|
|
|
|
import { SiteServerConfig, SiteServerResolutionMode } from "./types";
|
|
|
|
export function buildSiteUrl(params: { serverHost: string; serverResolution: SiteServerResolutionMode | (string & {}); siteId: string }): string {
|
|
return buildSiteUrlFromFields(params.serverHost, params.serverResolution, params.siteId);
|
|
}
|
|
|
|
export function buildSiteUrlFromServer(server: SiteServerConfig, siteId: string): string {
|
|
const protocol = server.host.startsWith("localhost") ? "http" : "https";
|
|
switch (server.resolutionMode) {
|
|
case "domain":
|
|
return `${protocol}://${server.host}`;
|
|
case "path":
|
|
return `${protocol}://${server.host}/${siteId}`;
|
|
case "subdomain":
|
|
return `${protocol}://${siteId}.${server.host}`;
|
|
default:
|
|
return `${protocol}://${server.host}/${siteId}`;
|
|
}
|
|
}
|
|
|
|
export function buildSiteUrlFromFields(serverHost: string, serverResolution: SiteServerResolutionMode | (string & {}), siteId: string): string {
|
|
const protocol = serverHost.startsWith("localhost") ? "http" : "https";
|
|
switch (serverResolution) {
|
|
case "domain":
|
|
return `${protocol}://${serverHost}`;
|
|
case "path":
|
|
return `${protocol}://${serverHost}/${siteId}`;
|
|
case "subdomain":
|
|
return `${protocol}://${siteId}.${serverHost}`;
|
|
default:
|
|
return `${protocol}://${serverHost}/${siteId}`;
|
|
}
|
|
}
|