33 lines
705 B
JavaScript
33 lines
705 B
JavaScript
'use strict';
|
|
|
|
const http = require('http'),
|
|
logger = require('winston');
|
|
|
|
const Server = require('./Server');
|
|
|
|
/**
|
|
* Class for creating an http server
|
|
*
|
|
* @extends Server
|
|
* @param {Express} app - current express instance
|
|
* @param {number} port - the port to listen on
|
|
*/
|
|
class HttpServer extends Server {
|
|
constructor(app, port) {
|
|
super();
|
|
let server = http.createServer(app);
|
|
server.listen(port);
|
|
server.on('error', this.onError);
|
|
server.on('listening', () => {
|
|
let addr = server.address();
|
|
let bind = typeof addr === 'string'
|
|
? `pipe ${addr}`
|
|
: `port ${addr.port}`;
|
|
logger.info(`Listening on ${bind}`);
|
|
});
|
|
|
|
this.server = server;
|
|
}
|
|
}
|
|
|
|
module.exports = HttpServer; |