2021-04-03 17:46:54 +00:00
|
|
|
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
|
exports.getListeningCb = exports.getErrorCb = void 0;
|
2021-06-05 11:58:50 +00:00
|
|
|
const errors_1 = require("./errors");
|
2021-04-03 17:46:54 +00:00
|
|
|
/**
|
|
|
|
* Event listener for HTTP server "error" event.
|
|
|
|
*
|
|
|
|
* @since 0.0.0
|
|
|
|
*/
|
|
|
|
function getErrorCb(port) {
|
|
|
|
return (error) => {
|
|
|
|
if (error.syscall !== 'listen') {
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
const bind = typeof port === 'string' ? 'Pipe ' + port : 'Port ' + port;
|
|
|
|
// handle specific listen errors with friendly messages
|
|
|
|
switch (error.code) {
|
|
|
|
case 'EACCES': {
|
|
|
|
console.error(bind + ' requires elevated privileges');
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
case 'EADDRINUSE': {
|
|
|
|
console.error(bind + ' is already in use');
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
exports.getErrorCb = getErrorCb;
|
|
|
|
/**
|
|
|
|
* Event listener for HTTP server "listening" event.
|
|
|
|
*
|
|
|
|
* @since 0.0.0
|
|
|
|
*/
|
|
|
|
function getListeningCb(server, debug) {
|
|
|
|
return () => {
|
|
|
|
const addr = server.address();
|
|
|
|
if (addr) {
|
|
|
|
const bind = typeof addr === 'string' ? 'pipe ' + addr : 'port ' + addr.port;
|
2021-06-05 11:58:50 +00:00
|
|
|
debug(`Listening on ${bind}`);
|
|
|
|
errors_1.consoleInfo(`Listening on ${bind}`);
|
2021-04-03 17:46:54 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
exports.getListeningCb = getListeningCb;
|