CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/database/settings/site-url.ts
Views: 687
1
import { getServerSettings } from "./server-settings";
2
import basePath from "@cocalc/backend/base-path";
3
4
// Returns url of this site in terms of the base path (determined
5
// by an env variable when server starts) and the "Domain name"
6
// setting of site settings. This URL does NOT end in a /
7
export default async function siteURL(dns?: string): Promise<string> {
8
if (!dns) {
9
dns = (await getServerSettings()).dns?.toLowerCase();
10
}
11
if (!dns) {
12
dns = "localhost";
13
}
14
if (!dns.startsWith("http")) {
15
dns = "https://" + dns;
16
}
17
return `${dns}${basePath == "/" ? "" : basePath}`;
18
}
19
20