mirror of https://github.com/status-im/codimd.git
refactor: Extract createHttpServer Function and Replace Temp with Query
Signed-off-by: BoHong Li <a60814billy@gmail.com>
This commit is contained in:
parent
8f9cfeec77
commit
0bed306ba9
47
app.js
47
app.js
|
@ -26,30 +26,33 @@ var response = require('./lib/response')
|
|||
var models = require('./lib/models')
|
||||
var csp = require('./lib/csp')
|
||||
|
||||
function createHttpServer () {
|
||||
if (config.useSSL) {
|
||||
const ca = (function () {
|
||||
let i, len, results
|
||||
results = []
|
||||
for (i = 0, len = config.sslCAPath.length; i < len; i++) {
|
||||
results.push(fs.readFileSync(config.sslCAPath[i], 'utf8'))
|
||||
}
|
||||
return results
|
||||
})()
|
||||
const options = {
|
||||
key: fs.readFileSync(config.sslKeyPath, 'utf8'),
|
||||
cert: fs.readFileSync(config.sslCertPath, 'utf8'),
|
||||
ca: ca,
|
||||
dhparam: fs.readFileSync(config.dhParamPath, 'utf8'),
|
||||
requestCert: false,
|
||||
rejectUnauthorized: false
|
||||
}
|
||||
return require('https').createServer(options, app)
|
||||
} else {
|
||||
return require('http').createServer(app)
|
||||
}
|
||||
}
|
||||
|
||||
// server setup
|
||||
var app = express()
|
||||
var server = null
|
||||
if (config.useSSL) {
|
||||
var ca = (function () {
|
||||
var i, len, results
|
||||
results = []
|
||||
for (i = 0, len = config.sslCAPath.length; i < len; i++) {
|
||||
results.push(fs.readFileSync(config.sslCAPath[i], 'utf8'))
|
||||
}
|
||||
return results
|
||||
})()
|
||||
var options = {
|
||||
key: fs.readFileSync(config.sslKeyPath, 'utf8'),
|
||||
cert: fs.readFileSync(config.sslCertPath, 'utf8'),
|
||||
ca: ca,
|
||||
dhparam: fs.readFileSync(config.dhParamPath, 'utf8'),
|
||||
requestCert: false,
|
||||
rejectUnauthorized: false
|
||||
}
|
||||
server = require('https').createServer(options, app)
|
||||
} else {
|
||||
server = require('http').createServer(app)
|
||||
}
|
||||
var server = createHttpServer()
|
||||
|
||||
// logger
|
||||
app.use(morgan('combined', {
|
||||
|
|
Loading…
Reference in New Issue