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/next/pages/api/v2/compute/get-servers.ts
Views: 687
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
9
import { apiRoute, apiRouteOperation } from "lib/api";
10
import {
11
GetComputeServersInputSchema,
12
GetComputeServersOutputSchema,
13
} from "lib/api/schema/compute/get-servers";
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
const { project_id, id } = getParams(req);
30
return await getServers({
31
account_id,
32
project_id,
33
id,
34
});
35
}
36
37
export default apiRoute({
38
getServers: apiRouteOperation({
39
method: "POST",
40
openApiOperation: {
41
tags: ["Compute"],
42
},
43
})
44
.input({
45
contentType: "application/json",
46
body: GetComputeServersInputSchema,
47
})
48
.outputs([
49
{
50
status: 200,
51
contentType: "application/json",
52
body: GetComputeServersOutputSchema,
53
},
54
])
55
.handler(handle),
56
});
57
58