Path: blob/master/src/packages/next/pages/api/conat/hub.ts
1697 views
/*1This is a bridge to call the Conat rpc api that is offered by the hub.2This is meant to be called by account users *NOT* the project. That's why3you must provide an api key for an account.45For security reasons this is ONLY usable via an API key -- using an account6is not allowed, since that opens us to XSS attacks.78Here is an example of how this would be used:910key=sk-...021112curl -sk -u $key: -H 'Content-Type: application/json' \13-d '{"name":"system.getNames", "args":[["d0bdabfd-850e-4c8d-8510-f6f1ecb9a5eb"]]}' \14http://localhost:9000/api/conat/hub1516The api is defined in packages/conat/hub/api/17*/1819import hubBridge from "@cocalc/server/api/hub-bridge";20import getParams from "lib/api/get-params";21import { getAccountFromApiKey } from "@cocalc/server/auth/api";2223export default async function handle(req, res) {24try {25const { account_id } = (await getAccountFromApiKey(req)) ?? {};26if (!account_id) {27throw Error(28"must be signed in and MUST provide an api key (cookies are not allowed)",29);30}31const { name, args, timeout } = getParams(req);32const resp = await hubBridge({ account_id, name, args, timeout });33res.json(resp);34} catch (err) {35res.json({ error: err.message });36}37}383940