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
23
app.js
23
app.js
|
@ -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()
|
if (config.useSSL) {
|
||||||
var server = null
|
const ca = (function () {
|
||||||
if (config.useSSL) {
|
let i, len, results
|
||||||
var ca = (function () {
|
|
||||||
var 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,11 +44,16 @@ 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', {
|
||||||
'stream': logger.stream
|
'stream': logger.stream
|
||||||
|
|
Loading…
Reference in New Issue