use reply.writeHead instead of reply.redirect to make sure httpall work

This commit is contained in:
陆柯 2021-11-28 15:28:47 +08:00
parent 9b2e72c19a
commit f407e8a6e9

View File

@ -124,16 +124,16 @@ if (typeof wo.envi.ssl === 'string') {
// })
// }else {
require('http')
.createServer(
server.all('*', function (ask, reply) {
reply.redirect(`https://${wo.envi.host}:${portHttps}`)
})
.createServer(function (ask, reply) {
reply.writeHead(301, { Location: `https://${ask.headers.host.replace(`:${portHttp}`, `:${portHttps}`)}${ask.url}` })
reply.end()
}
)
.listen(portHttp, function (err) {
if (err) console.log(err)
else
console.log(
`[${new Date().toJSON()}] Server redirecting from [${wo.envi.protocol}] http://${wo.envi.host}:${portHttp} with IPv4=${ipv4} for ${
`[${new Date().toJSON()}] Server redirecting from http://${wo.envi.host}:${portHttp} with IPv4=${ipv4} for ${
wo.envi.prodev
} environment`
)
@ -151,20 +151,17 @@ if (typeof wo.envi.ssl === 'string') {
if (err) console.log(err)
else
console.log(
`[${new Date().toJSON()}] Server listening on [${wo.envi.protocol}] https://${wo.envi.host}:${portHttps} with IPv4=${ipv4} for ${
`[${new Date().toJSON()}] Server listening on https://${wo.envi.host}:${portHttps} with IPv4=${ipv4} for ${
wo.envi.prodev
} environment`
)
})
// }
} else if ('redirectHttp2Https' === wo.envi.protocol) {
webServer = require('http')
.createServer(
server.all('*', function (ask, reply) {
reply.redirect(`https://${wo.envi.host}`)
portHttp = 80
webServer = server.all('*', function (ask, reply) {
reply.redirect(301, `https://${ask.headers.host.replace(`:${portHttp}`, `:${portHttps}`)}${ask.url}`)
})
// 或者 require('redirect-https')() // https://www.npmjs.com/package/redirect-https
)
.listen(portHttp, function (err) {
if (err) console.log(err)
else