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