This commit is contained in:
陆柯 2019-10-24 20:59:49 +08:00
parent b073f3185f
commit 9a5beef9b1

View File

@ -97,7 +97,7 @@ async function init(){ /*** 设置全局对象 ***/
if ('http' === wo.Config.protocol) {
webServer = require('http').createServer(server).listen(wo.Config.port, function (err) {
if (err) console.log(err)
else console.log(`Server listening on ${wo.Config.protocol}://${wo.Config.host}:${wo.Config.port} with IPv4=${ipv4} for ${server.settings.env} environment`)
else console.log(`[${new Date().toJSON()}] Server listening on ${wo.Config.protocol}://${wo.Config.host}:${wo.Config.port} with IPv4=${ipv4} for ${server.settings.env} environment`)
})
} else if ('https' === wo.Config.protocol) {
webServer = require('https').createServer(wo.Config.sslType === 'greenlock' ? greenlock.httpsOptions : {
@ -106,7 +106,7 @@ async function init(){ /*** 设置全局对象 ***/
// ca: [ fs.readFileSync(wo.Config.sslCA) ] // only for self-signed certificate: https://nodejs.org/api/tls.html#tls_tls_createserver_options_secureconnectionlistener
}, server).listen(wo.Config.port, function (err) {
if (err) console.log(err)
else console.log(`Server listening on ${wo.Config.protocol}://${wo.Config.host}:${wo.Config.port} with IPv4=${ipv4} for ${server.settings.env} environment`)
else console.log(`[${new Date().toJSON()}] Server listening on ${wo.Config.protocol}://${wo.Config.host}:${wo.Config.port} with IPv4=${ipv4} for ${server.settings.env} environment`)
})
} else if ('httpall' === wo.Config.protocol) {
let portHttp = wo.Config.port ? wo.Config.port : 80 // 如果port参数已设置使用它否则默认为80
@ -114,14 +114,14 @@ async function init(){ /*** 设置全局对象 ***/
if (wo.Config.sslType === 'greenlock') {
webServer = greenlock.listen(portHttp, portHttps, function (err) {
if (err) console.log(err)
else console.log(`Server listening on [${wo.Config.protocol}] http=>https://${wo.Config.host}:${portHttp}=>${portHttps} with IPv4=${ipv4} for ${server.settings.env} environment`)
else console.log(`[${new Date().toJSON()}] Server listening on [${wo.Config.protocol}] http=>https://${wo.Config.host}:${portHttp}=>${portHttps} with IPv4=${ipv4} for ${server.settings.env} environment`)
})
} else {
require('http').createServer(server.all('*', function (ask, reply) {
reply.redirect(`https://${wo.Config.host}:${portHttps}`)
})).listen(portHttp, function(err) {
if (err) console.log(err)
else console.log(`Server listening on [${wo.Config.protocol}] http://${wo.Config.host}:${portHttp} with IPv4=${ipv4} for ${server.settings.env} environment`)
else console.log(`[${new Date().toJSON()}] Server listening on [${wo.Config.protocol}] http://${wo.Config.host}:${portHttp} with IPv4=${ipv4} for ${server.settings.env} environment`)
})
webServer = require('https').createServer({
key: fs.readFileSync(wo.Config.sslKey),
@ -129,7 +129,7 @@ async function init(){ /*** 设置全局对象 ***/
// ca: [ fs.readFileSync(wo.Config.sslCA) ] // only for self-signed certificate: https://nodejs.org/api/tls.html#tls_tls_createserver_options_secureconnectionlistener
}, server).listen(portHttps, function (err) {
if (err) console.log(err)
else console.log(`Server listening on [${wo.Config.protocol}] https://${wo.Config.host}:${portHttps} with IPv4=${ipv4} for ${server.settings.env} environment`)
else console.log(`[${new Date().toJSON()}] Server listening on [${wo.Config.protocol}] https://${wo.Config.host}:${portHttps} with IPv4=${ipv4} for ${server.settings.env} environment`)
})
}
} else if ('http2https' === wo.Config.protocol) {
@ -138,7 +138,7 @@ async function init(){ /*** 设置全局对象 ***/
reply.redirect(`https://${wo.Config.host}`)
})).listen(wo.Config.port, function (err) {
if (err) console.log(err)
else console.log(`Server listening on ${wo.Config.protocol}://${wo.Config.host}:${wo.Config.port} with IPv4=${ipv4} for ${server.settings.env} environment`)
else console.log(`[${new Date().toJSON()}] Server listening on ${wo.Config.protocol}://${wo.Config.host}:${wo.Config.port} with IPv4=${ipv4} for ${server.settings.env} environment`)
})
}