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/google-cloud/get-pricing-data.ts
Views: 688
1
/*
2
Get pricing data.
3
4
This gets a json object that can be used to efficiently browse and get pricing data
5
about almost everything related to Google Cloud VM's. The idea is that this
6
is useful in itself, and also the module
7
@cocalc/util/compute/cloud/google-cloud/compute-cost
8
can run on the frontend, and takes this data to quickly compute total cost per hour
9
of a configuration.
10
11
We only allow api requests for signed in users to avoid abuse.
12
*/
13
14
import getAccountId from "lib/account/get-account";
15
import getPricingData from "@cocalc/server/compute/cloud/google-cloud/pricing-data";
16
17
export default async function handle(req, res) {
18
try {
19
res.json(await get(req));
20
} catch (err) {
21
res.json({ error: `${err.message}` });
22
return;
23
}
24
}
25
26
async function get(req) {
27
const account_id = await getAccountId(req);
28
if (!account_id) {
29
throw Error("must be signed in");
30
}
31
32
return await getPricingData();
33
}
34
35