From 4999207a6ec547d77c1fd72ffbb7cafb8637913f Mon Sep 17 00:00:00 2001 From: Roberto Tonino Date: Fri, 4 Jun 2021 21:37:27 +0200 Subject: [PATCH] chore(server): console feedback at server listening event --- server/src/app.ts | 7 +++++++ server/src/helpers/errors.ts | 2 +- server/src/helpers/server-callbacks.ts | 5 ++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/server/src/app.ts b/server/src/app.ts index b10eab0..c989cae 100644 --- a/server/src/app.ts +++ b/server/src/app.ts @@ -14,6 +14,7 @@ import { getErrorCb, getListeningCb } from './helpers/server-callbacks' import { registerApis } from './routes/api/register' import { registerWebsocket } from './websocket' import type { Arguments } from './types' +import { consoleInfo } from './helpers/errors' // TODO: Remove type assertion while keeping correct types const argv = yargs(hideBin(process.argv)).options({ @@ -49,6 +50,12 @@ if (process.env.NODE_ENV !== 'test') { registerWebsocket(wss) /* === Server callbacks === */ +app.on('mount', a => { + console.log(a) +}) +server.on('connect', () => { + consoleInfo('Server connected') +}) server.on('upgrade', (request, socket, head) => { wss.handleUpgrade(request, socket, head, socket => { wss.emit('connection', socket, request) diff --git a/server/src/helpers/errors.ts b/server/src/helpers/errors.ts index 5c98c05..bb4190f 100644 --- a/server/src/helpers/errors.ts +++ b/server/src/helpers/errors.ts @@ -2,7 +2,7 @@ import { concat } from 'ramda' const prependDeemix = concat('[deemix-server]: ') -export const consoleInfo = (errorText: string) => console.info(prependDeemix(errorText)) +export const consoleInfo = (infoText: string) => console.info(prependDeemix(infoText)) export const consoleError = (errorText: string) => console.error(prependDeemix(errorText)) export class BadRequestError extends Error { diff --git a/server/src/helpers/server-callbacks.ts b/server/src/helpers/server-callbacks.ts index 0aecdc4..3903914 100644 --- a/server/src/helpers/server-callbacks.ts +++ b/server/src/helpers/server-callbacks.ts @@ -1,5 +1,6 @@ import http from 'http' import type { Debugger } from 'debug' +import { consoleInfo } from './errors' /** * Event listener for HTTP server "error" event. @@ -41,7 +42,9 @@ export function getListeningCb(server: http.Server, debug: Debugger) { if (addr) { const bind = typeof addr === 'string' ? 'pipe ' + addr : 'port ' + addr.port - debug('Listening on ' + bind) + + debug(`Listening on ${bind}`) + consoleInfo(`Listening on ${bind}`) } } }