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.
ProgBlog/app/base/HttpsServer.js

34 lines
779 B
JavaScript
Raw Normal View History

2016-02-19 12:58:16 -05:00
'use strict';
const https = require('https'),
logger = require('winston');
const Server = require('./Server');
/**
* Class for creating an https server
*
* @extends Server
* @param {Express} app - current express instance
* @param {number} port - the port to listen on
* @param {Object} options - https server options
*/
class HttpsServer extends Server {
constructor(app, port, options) {
super();
let server = https.createServer(options, 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 = HttpsServer;