chore(server): console feedback at server listening event

This commit is contained in:
Roberto Tonino 2021-06-04 21:37:27 +02:00
parent 6617ece90c
commit 4999207a6e
3 changed files with 12 additions and 2 deletions

View File

@ -14,6 +14,7 @@ import { getErrorCb, getListeningCb } from './helpers/server-callbacks'
import { registerApis } from './routes/api/register' import { registerApis } from './routes/api/register'
import { registerWebsocket } from './websocket' import { registerWebsocket } from './websocket'
import type { Arguments } from './types' import type { Arguments } from './types'
import { consoleInfo } from './helpers/errors'
// TODO: Remove type assertion while keeping correct types // TODO: Remove type assertion while keeping correct types
const argv = yargs(hideBin(process.argv)).options({ const argv = yargs(hideBin(process.argv)).options({
@ -49,6 +50,12 @@ if (process.env.NODE_ENV !== 'test') {
registerWebsocket(wss) registerWebsocket(wss)
/* === Server callbacks === */ /* === Server callbacks === */
app.on('mount', a => {
console.log(a)
})
server.on('connect', () => {
consoleInfo('Server connected')
})
server.on('upgrade', (request, socket, head) => { server.on('upgrade', (request, socket, head) => {
wss.handleUpgrade(request, socket, head, socket => { wss.handleUpgrade(request, socket, head, socket => {
wss.emit('connection', socket, request) wss.emit('connection', socket, request)

View File

@ -2,7 +2,7 @@ import { concat } from 'ramda'
const prependDeemix = concat('[deemix-server]: ') 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 const consoleError = (errorText: string) => console.error(prependDeemix(errorText))
export class BadRequestError extends Error { export class BadRequestError extends Error {

View File

@ -1,5 +1,6 @@
import http from 'http' import http from 'http'
import type { Debugger } from 'debug' import type { Debugger } from 'debug'
import { consoleInfo } from './errors'
/** /**
* Event listener for HTTP server "error" event. * Event listener for HTTP server "error" event.
@ -41,7 +42,9 @@ export function getListeningCb(server: http.Server, debug: Debugger) {
if (addr) { if (addr) {
const bind = typeof addr === 'string' ? 'pipe ' + addr : 'port ' + addr.port const bind = typeof addr === 'string' ? 'pipe ' + addr : 'port ' + addr.port
debug('Listening on ' + bind)
debug(`Listening on ${bind}`)
consoleInfo(`Listening on ${bind}`)
} }
} }
} }