UNPKG

@cocalc/hub

Version:
35 lines 1.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseReq = void 0; function parseReq(url, // with base_path removed (url does start with /) remember_me // only impacts the key that is returned ) { if (url[0] != "/") { throw Error(`invalid url -- it should start with / but is "${url}"`); } const v = url.split("/").slice(1); const project_id = v[0]; if (v[1] != "port" && v[1] != "raw" && v[1] != "server") { throw Error(`invalid type -- "${v[1]}" must be "port", "raw" or "server" in url="${url}"`); } const type = v[1]; let internal_url = undefined; let port_desc; if (type == "raw") { port_desc = ""; } else if (type === "port") { port_desc = v[2]; } else if (type === "server") { port_desc = v[2]; internal_url = v.slice(3).join("/"); } else { throw Error(`unknown type "${type}"`); } let key = (remember_me ?? "") + project_id + type + port_desc + internal_url; return { key, type, project_id, port_desc, internal_url }; } exports.parseReq = parseReq; //# sourceMappingURL=parse.js.map