mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-20 00:23:03 +00:00
committed by
Rainer Killinger
parent
42c7350c36
commit
8b457c9911
20
src/cli.ts
20
src/cli.ts
@@ -13,13 +13,14 @@
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {Logger} from '@openstapps/logger';
|
||||
import * as http from 'http';
|
||||
import {app} from './app';
|
||||
import {logger} from './common';
|
||||
|
||||
/**
|
||||
* Get port from environment and store in Express.
|
||||
*/
|
||||
// tslint:disable-next-line: strict-boolean-expressions
|
||||
const port = normalizePort(process.env.PORT || '3000');
|
||||
// TODO: Can we remove that? It doesn't look like it is read at all.
|
||||
app.set('port', port);
|
||||
@@ -58,23 +59,24 @@ function normalizePort(value: string) {
|
||||
/**
|
||||
* Event listener for HTTP server "error" event.
|
||||
*/
|
||||
function onError(error: Error | any) {
|
||||
// tslint:disable-next-line: completed-docs
|
||||
async function onError(error: { code: string; syscall: string; }) {
|
||||
if (error.syscall !== 'listen') {
|
||||
throw error;
|
||||
}
|
||||
|
||||
const bind = typeof port === 'string'
|
||||
? 'Pipe ' + port
|
||||
: 'Port ' + port;
|
||||
? `Pipe ${port}`
|
||||
: `Port ${port}`;
|
||||
|
||||
// handle specific listen errors with friendly messages
|
||||
switch (error.code) {
|
||||
case 'EACCES':
|
||||
logger.error(bind + ' requires elevated privileges');
|
||||
await Logger.error(`${bind} requires elevated privileges`);
|
||||
process.exit(1);
|
||||
break;
|
||||
case 'EADDRINUSE':
|
||||
logger.error(bind + ' is already in use');
|
||||
await Logger.error(`${bind} is already in use`);
|
||||
process.exit(1);
|
||||
break;
|
||||
default:
|
||||
@@ -88,7 +90,7 @@ function onError(error: Error | any) {
|
||||
function onListening() {
|
||||
const addr = server.address();
|
||||
const bind = typeof addr === 'string'
|
||||
? 'pipe ' + addr
|
||||
: 'port ' + addr.port;
|
||||
logger.ok('Listening on ' + bind);
|
||||
? `pipe ${addr}`
|
||||
: `port ${addr.port}`;
|
||||
Logger.ok(`Listening on ${bind}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user