|
|
@ -5,7 +5,6 @@ |
|
|
|
'use strict' |
|
|
|
|
|
|
|
const fs = require('fs') |
|
|
|
const https = require('https') |
|
|
|
const express = require('express') |
|
|
|
const helmet = require('helmet') |
|
|
|
const Logger = require('../logger') |
|
|
@ -19,15 +18,11 @@ class HttpServer { |
|
|
|
/** |
|
|
|
* Constructor |
|
|
|
* @param {int} port - port used by the http server |
|
|
|
* @param {object} httpsOptions - https options |
|
|
|
*/ |
|
|
|
constructor(port, httpsOptions) { |
|
|
|
constructor(port) { |
|
|
|
// Initialize server port
|
|
|
|
this.port = port |
|
|
|
|
|
|
|
// Store https options
|
|
|
|
this.httpsOptions = httpsOptions |
|
|
|
|
|
|
|
// Listening server instance
|
|
|
|
this.server = null |
|
|
|
|
|
|
@ -58,30 +53,10 @@ class HttpServer { |
|
|
|
HttpServer.sendError(res, ret, 500) |
|
|
|
}) |
|
|
|
|
|
|
|
if (this.httpsOptions == null || !this.httpsOptions.active) { |
|
|
|
// Start a http server
|
|
|
|
this.server = this.app.listen(this.port, () => { |
|
|
|
Logger.info('HTTP server listening on port ' + this.port) |
|
|
|
}) |
|
|
|
} else { |
|
|
|
// Start a https server
|
|
|
|
const options = { |
|
|
|
key: fs.readFileSync(this.httpsOptions.keypath), |
|
|
|
cert: fs.readFileSync(this.httpsOptions.certpath), |
|
|
|
requestCert: false, |
|
|
|
rejectUnauthorized: false |
|
|
|
} |
|
|
|
|
|
|
|
if (this.httpsOptions.capath) |
|
|
|
options.ca = fs.readFileSync(this.httpsOptions.capath) |
|
|
|
|
|
|
|
if (this.httpsOptions.passphrase) |
|
|
|
options.passphrase = this.httpsOptions.passphrase |
|
|
|
|
|
|
|
this.server = https.createServer(options, this.app).listen(this.port, () => { |
|
|
|
Logger.info('HTTPS server listening on port ' + this.port) |
|
|
|
}) |
|
|
|
} |
|
|
|
// Start a http server
|
|
|
|
this.server = this.app.listen(this.port, () => { |
|
|
|
Logger.info('HTTP server listening on port ' + this.port) |
|
|
|
}) |
|
|
|
|
|
|
|
this.server.timeout = 600 * 1000 |
|
|
|
// @see https://github.com/nodejs/node/issues/13391
|
|
|
|