34 lines
779 B
JavaScript
34 lines
779 B
JavaScript
'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; |