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/create-server.ts
Views: 687
1
/*
2
Create a compute server
3
*/
4
5
import getAccountId from "lib/account/get-account";
6
import createServer from "@cocalc/server/compute/create-server";
7
import getParams from "lib/api/get-params";
8
9
import { apiRoute, apiRouteOperation } from "lib/api";
10
import {
11
CreateServerInputSchema,
12
CreateServerOutputSchema
13
} from "lib/api/schema/compute/create-server";
14
15
16
async function handle(req, res) {
17
try {
18
res.json(await get(req));
19
} catch (err) {
20
res.json({ error: `${err.message}` });
21
return;
22
}
23
}
24
25
async function get(req) {
26
const account_id = await getAccountId(req);
27
if (!account_id) {
28
throw Error("must be signed in");
29
}
30
const {
31
project_id,
32
title,
33
color,
34
idle_timeout,
35
autorestart,
36
cloud,
37
configuration,
38
notes,
39
} = getParams(req);
40
return await createServer({
41
account_id,
42
project_id,
43
title,
44
color,
45
idle_timeout,
46
autorestart,
47
cloud,
48
configuration,
49
notes,
50
});
51
}
52
53
export default apiRoute({
54
createServer: apiRouteOperation({
55
method: "POST",
56
openApiOperation: {
57
tags: ["Compute"]
58
},
59
})
60
.input({
61
contentType: "application/json",
62
body: CreateServerInputSchema,
63
})
64
.outputs([
65
{
66
status: 200,
67
contentType: "application/json",
68
body: CreateServerOutputSchema,
69
},
70
])
71
.handler(handle),
72
});
73
74