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/hub/servers/app/customize.ts
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import { send as sendManifest } from "@cocalc/hub/manifest";
7
import { WebappConfiguration } from "@cocalc/hub/webapp-configuration";
8
import { database } from "../database";
9
10
export default function init(router, isPersonal: boolean) {
11
const webappConfig = new WebappConfiguration({ db: database });
12
13
router.get("/customize", async (req, res) => {
14
// If we're behind cloudflare, we expose the detected country in the client.
15
// Use a lib like https://github.com/michaelwittig/node-i18n-iso-countries
16
// to read the ISO 3166-1 Alpha 2 codes.
17
// If it is unknown, the code will be XX. "K1" is the Tor-Network.
18
const country = req.headers["cf-ipcountry"] ?? "XX";
19
const host = req.headers["host"];
20
const config = await webappConfig.get({ host, country });
21
if (isPersonal) {
22
config.configuration.is_personal = true;
23
}
24
if (req.query.type === "manifest") {
25
// Used for progressive webapp info.
26
sendManifest(res, config);
27
} else {
28
// Otherwise, just send the data back as json, for the client to parse.
29
res.json(config);
30
}
31
});
32
}
33
34