2018-09-28 11:35:21 +02:00
|
|
|
/**
|
|
|
|
* @prettier
|
2018-10-01 07:06:30 +02:00
|
|
|
* @flow
|
2018-09-28 11:35:21 +02:00
|
|
|
*/
|
|
|
|
|
2018-09-22 12:54:21 +02:00
|
|
|
import path from 'path';
|
|
|
|
|
2018-10-01 07:06:30 +02:00
|
|
|
import { parseAddress } from '../utils';
|
|
|
|
import { DEFAULT_PORT } from '../constants';
|
2018-09-22 12:54:21 +02:00
|
|
|
|
|
|
|
const logger = require('../logger');
|
|
|
|
|
|
|
|
export const resolveConfigPath = function(storageLocation: string, file: string) {
|
|
|
|
return path.resolve(path.dirname(storageLocation), file);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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}
|
|
|
|
*/
|
2019-08-16 21:20:18 +02:00
|
|
|
export function getListListenAddresses(argListen: string, configListen: any): any {
|
2018-09-22 12:54:21 +02:00
|
|
|
// command line || config file || default
|
|
|
|
let addresses;
|
|
|
|
if (argListen) {
|
|
|
|
addresses = [argListen];
|
|
|
|
} else if (Array.isArray(configListen)) {
|
|
|
|
addresses = configListen;
|
|
|
|
} else if (configListen) {
|
|
|
|
addresses = [configListen];
|
|
|
|
} else {
|
|
|
|
addresses = [DEFAULT_PORT];
|
|
|
|
}
|
2018-09-28 11:35:21 +02:00
|
|
|
addresses = addresses
|
2019-08-16 21:20:18 +02:00
|
|
|
.map(function(addr): string {
|
2018-09-28 11:35:21 +02:00
|
|
|
const parsedAddr = parseAddress(addr);
|
|
|
|
|
|
|
|
if (!parsedAddr) {
|
|
|
|
logger.logger.warn(
|
2018-10-01 07:06:30 +02:00
|
|
|
{ addr: addr },
|
2018-09-28 11:35:21 +02:00
|
|
|
'invalid address - @{addr}, we expect a port (e.g. "4873"),' + ' host:port (e.g. "localhost:4873") or full url' + ' (e.g. "http://localhost:4873/")'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return parsedAddr;
|
|
|
|
})
|
|
|
|
.filter(Boolean);
|
2018-09-22 12:54:21 +02:00
|
|
|
|
|
|
|
return addresses;
|
|
|
|
}
|