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