@cocalc/hub
Version:
CoCalc: Backend webserver component
24 lines • 1.25 kB
JavaScript
;
/*
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
* License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const logger_1 = __importDefault(require("../logger"));
const handle_request_1 = __importDefault(require("./handle-request"));
const handle_upgrade_1 = __importDefault(require("./handle-upgrade"));
const base_path_1 = __importDefault(require("@cocalc/backend/base-path"));
const winston = (0, logger_1.default)("proxy");
function init(opts) {
const proxy_regexp = `^${base_path_1.default.length <= 1 ? "" : base_path_1.default}\/[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}\/*`;
winston.info(`creating proxy server with proxy_regexp="${proxy_regexp}"`);
const handleProxy = (0, handle_request_1.default)(opts);
const handleUpgrade = (0, handle_upgrade_1.default)(opts, proxy_regexp);
opts.app.all(proxy_regexp, handleProxy);
opts.httpServer.on("upgrade", handleUpgrade);
}
exports.default = init;
//# sourceMappingURL=index.js.map