UNPKG

smc-hub

Version:

CoCalc: Backend webserver component

51 lines (50 loc) 2.11 kB
"use strict"; /* Save other paths in # part of URL then redirect to the single page app. That this happened is assumed, e.g., in packages/static/src/init-app-base-path.ts This redirect is *undone* in smc-webapp/client/handle-hash-url.ts */ var __values = (this && this.__values) || function(o) { var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; if (m) return m.call(o); if (o && typeof o.length === "number") return { next: function () { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var url_1 = require("url"); var path_1 = require("path"); var base_path_1 = __importDefault(require("smc-util-node/base-path")); // All top level page "entry points" in the webapp must be listed here. // Should be consistent with what is handled in smc-webapp/history.ts // and smc-webapp/app/actions.ts var ROUTES = ["admin", "help", "projects", "settings", "notifications"]; function init(router) { var e_1, _a; var v = []; try { for (var ROUTES_1 = __values(ROUTES), ROUTES_1_1 = ROUTES_1.next(); !ROUTES_1_1.done; ROUTES_1_1 = ROUTES_1.next()) { var path = ROUTES_1_1.value; v.push("/" + path + "*"); } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (ROUTES_1_1 && !ROUTES_1_1.done && (_a = ROUTES_1.return)) _a.call(ROUTES_1); } finally { if (e_1) throw e_1.error; } } router.get(v, function (req, res) { var q = url_1.parse(req.url, true).search || ""; // gives exactly "?key=value,key=..." res.redirect(path_1.join(base_path_1.default, "static/app.html#") + req.path.slice(1) + q); }); } exports.default = init; //# sourceMappingURL=app-redirect.js.map