|
@ -30,7 +30,14 @@ class HttpServer { |
|
|
this.server = null |
|
|
this.server = null |
|
|
|
|
|
|
|
|
// Initialize the tiny-http app
|
|
|
// Initialize the tiny-http app
|
|
|
this.app = new App(); |
|
|
this.app = new App({ |
|
|
|
|
|
// Error handler
|
|
|
|
|
|
onError: (err, req, res) => { |
|
|
|
|
|
Logger.error(err.stack, 'HttpServer : general error') |
|
|
|
|
|
const ret = {status: 'Server error'} |
|
|
|
|
|
HttpServer.sendError(res, ret, 500) |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
this.app.set('trust proxy', 'loopback') |
|
|
this.app.set('trust proxy', 'loopback') |
|
|
|
|
|
|
|
|
// Middlewares for json responses and requests logging
|
|
|
// Middlewares for json responses and requests logging
|
|
@ -50,14 +57,6 @@ class HttpServer { |
|
|
* @returns {object} returns the listening server instance |
|
|
* @returns {object} returns the listening server instance |
|
|
*/ |
|
|
*/ |
|
|
start() { |
|
|
start() { |
|
|
// Error handler, should be final middleware
|
|
|
|
|
|
this.app.use(function(err, req, res, next) { |
|
|
|
|
|
if (res.headersSent) return next(err) |
|
|
|
|
|
Logger.error(err.stack, 'HttpServer : start()') |
|
|
|
|
|
const ret = {status: 'Server error'} |
|
|
|
|
|
HttpServer.sendError(res, ret, 500) |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
// Start a http server
|
|
|
// Start a http server
|
|
|
this.server = this.app.listen(this.port, this.host, () => { |
|
|
this.server = this.app.listen(this.port, this.host, () => { |
|
|
Logger.info(`HttpServer : Listening on ${this.host}:${this.port}`) |
|
|
Logger.info(`HttpServer : Listening on ${this.host}:${this.port}`) |
|
|