UNPKG

@cocalc/project

Version:
56 lines (45 loc) 1.5 kB
// Generated by CoffeeScript 2.5.1 (function() { //######################################################################## // This file is part of CoCalc: Copyright © 2020 Sagemath, Inc. // License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details //######################################################################## /* The port_manager manages the ports for the various servers. It reads the port from memory or from disk and returns it. */ var SMC, fs, misc_node, port_file, ports; fs = require('fs'); misc_node = require('@cocalc/backend/misc_node'); SMC = process.env.SMC; exports.port_file = port_file = function(type) { return `${SMC}/${type}_server/${type}_server.port`; }; ports = {}; exports.get_port = function(type, cb) { // cb(err, port number) if (ports[type] != null) { return cb(false, ports[type]); } else { return fs.readFile(misc_node.abspath(port_file(type)), function(err, content) { var e; if (err) { return cb(err); } else { try { ports[type] = parseInt(content); return cb(false, ports[type]); } catch (error) { e = error; return cb(`${type}_server port file corrupted`); } } }); } }; exports.forget_port = function(type) { if (ports[type] != null) { return delete ports[type]; } }; }).call(this); //# sourceMappingURL=port_manager.js.map