Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/next/pages/api/v2/compute/is-dns-available.ts
1451 views
1
/*
2
Check if DNS subdomain is available.
3
*/
4
5
import getAccountId from "lib/account/get-account";
6
import { isDnsAvailable } from "@cocalc/server/compute/dns";
7
import getParams from "lib/api/get-params";
8
import throttle from "@cocalc/util/api/throttle";
9
10
export default async function handle(req, res) {
11
try {
12
res.json(await get(req));
13
} catch (err) {
14
res.json({ error: `${err.message}` });
15
return;
16
}
17
}
18
19
async function get(req) {
20
const account_id = await getAccountId(req);
21
if (!account_id) {
22
throw Error("must be signed in");
23
}
24
throttle({
25
account_id,
26
endpoint: "compute/is-dns-available",
27
});
28
const { dns } = getParams(req);
29
return {
30
isAvailable: await isDnsAvailable(dns),
31
};
32
}
33
34