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. Commercial Alternative to JupyterHub.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/next/pages/api/v2/compute/get-servers.ts
Views: 923
1
/*
2
Get compute servers
3
*/
4
5
import getAccountId from "lib/account/get-account";
6
import getServers from "@cocalc/server/compute/get-servers";
7
import getParams from "lib/api/get-params";
8
import { apiRoute, apiRouteOperation } from "lib/api";
9
import {
10
GetComputeServersInputSchema,
11
GetComputeServersOutputSchema,
12
} from "lib/api/schema/compute/get-servers";
13
import throttle from "@cocalc/util/api/throttle";
14
15
async function handle(req, res) {
16
try {
17
res.json(await get(req));
18
} catch (err) {
19
res.json({ error: `${err.message}` });
20
return;
21
}
22
}
23
24
async function get(req) {
25
const account_id = await getAccountId(req);
26
if (!account_id) {
27
throw Error("must be signed in");
28
}
29
throttle({
30
account_id,
31
endpoint: "compute/get-servers",
32
});
33
const { project_id, id } = getParams(req);
34
return await getServers({
35
account_id,
36
project_id,
37
id,
38
});
39
}
40
41
export default apiRoute({
42
getServers: apiRouteOperation({
43
method: "POST",
44
openApiOperation: {
45
tags: ["Compute"],
46
},
47
})
48
.input({
49
contentType: "application/json",
50
body: GetComputeServersInputSchema,
51
})
52
.outputs([
53
{
54
status: 200,
55
contentType: "application/json",
56
body: GetComputeServersOutputSchema,
57
},
58
])
59
.handler(handle),
60
});
61
62