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