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