This repository has been archived on 2018-10-12. You can view files and clone it, but cannot push or open issues or pull requests.
crispy-train/app/base/HttpServer.js

33 lines
705 B
JavaScript
Raw Normal View History

2016-02-18 21:50:45 -05:00
'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;