Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/hub/proxy/parse.ts
Views: 687
type ProxyType = "port" | "raw" | "server";12export function parseReq(3url: string, // with base_path removed (url does start with /)4remember_me?: string, // only impacts the key that is returned5api_key?: string // only impacts key6): {7key: string; // used for caching8type: ProxyType;9project_id: string; // the uuid of the target project containing the service being proxied10port_desc: string; // description of port; "" for raw, or a number or "jupyter"11internal_url: string | undefined; // url at target of thing we are proxying to; this is ONLY set in case type == 'server'.12} {13if (url[0] != "/") {14throw Error(`invalid url -- it should start with / but is "${url}"`);15}16const v = url.split("/").slice(1);17const project_id = v[0];18if (v[1] != "port" && v[1] != "raw" && v[1] != "server") {19throw Error(20`invalid type -- "${v[1]}" must be "port", "raw" or "server" in url="${url}"`21);22}23const type: ProxyType = v[1];24let internal_url: string | undefined = undefined;25let port_desc: string;26if (type == "raw") {27port_desc = "";28} else if (type === "port") {29port_desc = v[2];30} else if (type === "server") {31port_desc = v[2];32internal_url = v.slice(3).join("/");33} else {34throw Error(`unknown type "${type}"`);35}36const key = `${remember_me}-${api_key}-${project_id}-${type}-${port_desc}-${internal_url}`;37return { key, type, project_id, port_desc, internal_url };38}394041