UNPKG

verdaccio

Version:

A lightweight private npm proxy registry

190 lines (154 loc) 24.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.startVerdaccio = startVerdaccio; exports.listenDefaultCallback = listenDefaultCallback; var _url = _interopRequireDefault(require("url")); var _fs = _interopRequireDefault(require("fs")); var _http = _interopRequireDefault(require("http")); var _https = _interopRequireDefault(require("https")); var _constants = _interopRequireDefault(require("constants")); var _lodash = require("lodash"); var _index = _interopRequireDefault(require("../api/index")); var _constants2 = require("./constants"); var _utils = require("./cli/utils"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } const logger = require('./logger'); function displayExperimentsInfoBox(experiments) { const experimentList = Object.keys(experiments); if (experimentList.length >= 1) { logger.logger.warn('⚠️ experiments are enabled, we recommend do not use experiments in production, comment out this section to disable it'); experimentList.forEach(experiment => { logger.logger.warn(` - support for ${experiment} ${experiments[experiment] ? 'is enabled' : ' is disabled'}`); }); } } /** * Trigger the server after configuration has been loaded. * @param {Object} config * @param {Object} cliArguments * @param {String} configPath * @param {String} pkgVersion * @param {String} pkgName */ function startVerdaccio(config, cliListen, configPath, pkgVersion, pkgName, callback) { if ((0, _lodash.isObject)(config) === false) { throw new Error(_constants2.API_ERROR.CONFIG_BAD_FORMAT); } if ('experiments' in config) { displayExperimentsInfoBox(config.experiments); } (0, _index.default)(config).then(app => { const addresses = (0, _utils.getListListenAddresses)(cliListen, config.listen); addresses.forEach(function (addr) { let webServer; if (addr.proto === 'https') { webServer = handleHTTPS(app, configPath, config); } else { // http webServer = _http.default.createServer(app); } if (config.server && typeof config.server.keepAliveTimeout !== 'undefined' && config.server.keepAliveTimeout !== 'null') { // library definition for node is not up to date (doesn't contain recent 8.0 changes) webServer.keepAliveTimeout = config.server.keepAliveTimeout * 1000; } unlinkAddressPath(addr); callback(webServer, addr, pkgName, pkgVersion); }); }); } function unlinkAddressPath(addr) { if (addr.path && _fs.default.existsSync(addr.path)) { _fs.default.unlinkSync(addr.path); } } function logHTTPSWarning(storageLocation) { logger.logger.fatal(['You have enabled HTTPS and need to specify either ', ' "https.key" and "https.cert" or ', ' "https.pfx" and optionally "https.passphrase" ', 'to run https server', '', // commands are borrowed from node.js docs 'To quickly create self-signed certificate, use:', ' $ openssl genrsa -out ' + (0, _utils.resolveConfigPath)(storageLocation, _constants2.keyPem) + ' 2048', ' $ openssl req -new -sha256 -key ' + (0, _utils.resolveConfigPath)(storageLocation, _constants2.keyPem) + ' -out ' + (0, _utils.resolveConfigPath)(storageLocation, _constants2.csrPem), ' $ openssl x509 -req -in ' + (0, _utils.resolveConfigPath)(storageLocation, _constants2.csrPem) + ' -signkey ' + (0, _utils.resolveConfigPath)(storageLocation, _constants2.keyPem) + ' -out ' + (0, _utils.resolveConfigPath)(storageLocation, _constants2.certPem), '', 'And then add to config file (' + storageLocation + '):', ' https:', ` key: ${(0, _utils.resolveConfigPath)(storageLocation, _constants2.keyPem)}`, ` cert: ${(0, _utils.resolveConfigPath)(storageLocation, _constants2.certPem)}`].join('\n')); process.exit(2); } function handleHTTPS(app, configPath, config) { try { let httpsOptions = { secureOptions: _constants.default.SSL_OP_NO_SSLv2 | _constants.default.SSL_OP_NO_SSLv3 // disable insecure SSLv2 and SSLv3 }; const keyCertConfig = config.https; const pfxConfig = config.https; // https must either have key and cert or a pfx and (optionally) a passphrase if (!(keyCertConfig.key && keyCertConfig.cert || pfxConfig.pfx)) { logHTTPSWarning(configPath); } if (pfxConfig.pfx) { const { pfx, passphrase } = pfxConfig; httpsOptions = (0, _lodash.assign)(httpsOptions, { pfx: _fs.default.readFileSync(pfx), passphrase: passphrase || '' }); } else { const { key, cert, ca } = keyCertConfig; httpsOptions = (0, _lodash.assign)(httpsOptions, _objectSpread({ key: _fs.default.readFileSync(key), cert: _fs.default.readFileSync(cert) }, ca && { ca: _fs.default.readFileSync(ca) })); } return _https.default.createServer(httpsOptions, app); } catch (err) { // catch errors related to certificate loading logger.logger.fatal({ err: err }, 'cannot create server: @{err.message}'); process.exit(2); } } function listenDefaultCallback(webServer, addr, pkgName, pkgVersion) { const server = webServer.listen(addr.port || addr.path, addr.host, () => { // send a message for tests if ((0, _lodash.isFunction)(process.send)) { process.send({ verdaccio_started: true }); } }).on('error', function (err) { logger.logger.fatal({ err: err }, 'cannot create server: @{err.message}'); process.exit(2); }); function handleShutdownGracefully() { logger.logger.fatal('received shutdown signal - closing server gracefully...'); server.close(() => { logger.logger.info('server closed.'); process.exit(0); }); } // handle shutdown signals nicely when environment says so if (process.env.VERDACCIO_HANDLE_KILL_SIGNALS === 'true') { process.on('SIGINT', handleShutdownGracefully); process.on('SIGTERM', handleShutdownGracefully); process.on('SIGHUP', handleShutdownGracefully); } logger.logger.warn({ addr: addr.path ? _url.default.format({ protocol: 'unix', pathname: addr.path }) : _url.default.format({ protocol: addr.proto, hostname: addr.host, port: addr.port, pathname: '/' }), version: pkgName + '/' + pkgVersion }, 'http address - @{addr} - @{version}'); } //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9saWIvYm9vdHN0cmFwLnR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