@verdaccio/node-api
Version:
node API
86 lines (84 loc) • 2.72 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.DEFAULT_PROTOCOL = exports.DEFAULT_PORT = exports.DEFAULT_DOMAIN = void 0;
exports.getListListenAddresses = getListListenAddresses;
exports.parseAddress = parseAddress;
var _core = require("@verdaccio/core");
const DEFAULT_PORT = '4873';
exports.DEFAULT_PORT = DEFAULT_PORT;
const DEFAULT_PROTOCOL = 'http';
exports.DEFAULT_PROTOCOL = DEFAULT_PROTOCOL;
const DEFAULT_DOMAIN = 'localhost';
/**
* Parse an internet address
* Allow:
- https:localhost:1234 - protocol + host + port
- localhost:1234 - host + port
- 1234 - port
- http::1234 - protocol + port
- https://localhost:443/ - full url + https
- http://[::1]:443/ - ipv6
- unix:/tmp/http.sock - unix sockets
- https://unix:/tmp/http.sock - unix sockets (https)
* @param {*} urlAddress the internet address definition
* @return {Object|Null} literal object that represent the address parsed
*/
exports.DEFAULT_DOMAIN = DEFAULT_DOMAIN;
function parseAddress(urlAddress) {
//
// TODO: refactor it to something more reasonable?
//
// protocol : // ( host )|( ipv6 ): port /
let urlPattern = /^((https?):(\/\/)?)?((([^\/:]*)|\[([^\[\]]+)\]):)?(\d+)\/?$/.exec(urlAddress);
if (urlPattern) {
return {
proto: urlPattern[2] || DEFAULT_PROTOCOL,
host: urlPattern[6] || urlPattern[7] || DEFAULT_DOMAIN,
port: urlPattern[8] || DEFAULT_PORT
};
}
urlPattern = /^((https?):(\/\/)?)?unix:(.*)$/.exec(urlAddress);
if (urlPattern) {
return {
proto: urlPattern[2] || DEFAULT_PROTOCOL,
path: urlPattern[4]
};
}
return null;
}
/**
* Retrieve all addresses defined in the config file.
* Verdaccio is able to listen multiple ports
* @param {String} argListen
* @param {String} configListen
* eg:
* listen:
- localhost:5555
- localhost:5557
@return {Array}
*/
function getListListenAddresses(argListen, configListen) {
// command line || config file || default
let addresses;
if (argListen) {
addresses = [argListen];
} else if (Array.isArray(configListen)) {
addresses = configListen;
process.emitWarning('multiple addresses will be deprecated in the next major, only use one');
} else if (configListen) {
addresses = [configListen];
} else {
addresses = [DEFAULT_PORT];
}
addresses = addresses.map(function (addr) {
const parsedAddr = parseAddress(addr);
if (!parsedAddr) {
_core.warningUtils.emit(_core.warningUtils.Codes.VERWAR004, addr);
}
return parsedAddr;
}).filter(Boolean);
return addresses;
}
//# sourceMappingURL=cli-utils.js.map