refactor: Extract createHttpServer Function and Replace Temp with Query

Signed-off-by: BoHong Li <a60814billy@gmail.com>
This commit is contained in:
BoHong Li 2019-04-20 01:30:26 +08:00
parent 8f9cfeec77
commit 0bed306ba9
No known key found for this signature in database
GPG Key ID: 9696D5590D58290F
1 changed files with 25 additions and 22 deletions

19
app.js
View File

@ -26,19 +26,17 @@ var response = require('./lib/response')
var models = require('./lib/models') var models = require('./lib/models')
var csp = require('./lib/csp') var csp = require('./lib/csp')
// server setup function createHttpServer () {
var app = express()
var server = null
if (config.useSSL) { if (config.useSSL) {
var ca = (function () { const ca = (function () {
var i, len, results let i, len, results
results = [] results = []
for (i = 0, len = config.sslCAPath.length; i < len; i++) { for (i = 0, len = config.sslCAPath.length; i < len; i++) {
results.push(fs.readFileSync(config.sslCAPath[i], 'utf8')) results.push(fs.readFileSync(config.sslCAPath[i], 'utf8'))
} }
return results return results
})() })()
var options = { const options = {
key: fs.readFileSync(config.sslKeyPath, 'utf8'), key: fs.readFileSync(config.sslKeyPath, 'utf8'),
cert: fs.readFileSync(config.sslCertPath, 'utf8'), cert: fs.readFileSync(config.sslCertPath, 'utf8'),
ca: ca, ca: ca,
@ -46,10 +44,15 @@ if (config.useSSL) {
requestCert: false, requestCert: false,
rejectUnauthorized: false rejectUnauthorized: false
} }
server = require('https').createServer(options, app) return require('https').createServer(options, app)
} else { } else {
server = require('http').createServer(app) return require('http').createServer(app)
} }
}
// server setup
var app = express()
var server = createHttpServer()
// logger // logger
app.use(morgan('combined', { app.use(morgan('combined', {