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/util/compute/dns.ts
Views: 687
1
import { valid_dns_name } from "@cocalc/util/db-schema/site-defaults";
2
import { isReserved } from "@cocalc/util/db-schema/name-rules";
3
4
// cost right now for DNS
5
export const DNS_COST_PER_MONTH = 5;
6
export const DNS_COST_PER_HOUR = DNS_COST_PER_MONTH / 730;
7
8
export function checkValidDomain(name) {
9
if (isReserved(name)) {
10
throw Error(`${name} is not available`);
11
}
12
if (typeof name != "string") {
13
throw Error("name must be a string");
14
}
15
if (!valid_dns_name(name)) {
16
throw Error("letters and dashes are allowed");
17
}
18
if (name.includes(".")) {
19
throw Error("dots . are not allowed");
20
}
21
if (name.length > 63 || name.length == 0) {
22
throw Error("name must be between 1 and 63 characters");
23
}
24
if (name[0] == "-" || name[name.length - 1] == "-") {
25
throw Error("name must not start or end with a dash");
26
}
27
}
28
29