use reply.writeHead instead of reply.redirect to make sure httpall work
This commit is contained in:
parent
9b2e72c19a
commit
f407e8a6e9
57
server.js
57
server.js
@ -123,21 +123,21 @@ if (typeof wo.envi.ssl === 'string') {
|
|||||||
// else console.log(`Server listening on [${wo.wo.envi.protocol}] http=>https://${wo.wo.envi.host}:${portHttp}=>${portHttps} for ${server.settings.env} environment`)
|
// else console.log(`Server listening on [${wo.wo.envi.protocol}] http=>https://${wo.wo.envi.host}:${portHttp}=>${portHttps} for ${server.settings.env} environment`)
|
||||||
// })
|
// })
|
||||||
// }else {
|
// }else {
|
||||||
require('http')
|
require('http')
|
||||||
.createServer(
|
.createServer(function (ask, reply) {
|
||||||
server.all('*', function (ask, reply) {
|
reply.writeHead(301, { Location: `https://${ask.headers.host.replace(`:${portHttp}`, `:${portHttps}`)}${ask.url}` })
|
||||||
reply.redirect(`https://${wo.envi.host}:${portHttps}`)
|
reply.end()
|
||||||
})
|
}
|
||||||
)
|
)
|
||||||
.listen(portHttp, function (err) {
|
.listen(portHttp, function (err) {
|
||||||
if (err) console.log(err)
|
if (err) console.log(err)
|
||||||
else
|
else
|
||||||
console.log(
|
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
|
wo.envi.prodev
|
||||||
} environment`
|
} environment`
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
webServer = require('https')
|
webServer = require('https')
|
||||||
.createServer(
|
.createServer(
|
||||||
{
|
{
|
||||||
@ -151,27 +151,24 @@ if (typeof wo.envi.ssl === 'string') {
|
|||||||
if (err) console.log(err)
|
if (err) console.log(err)
|
||||||
else
|
else
|
||||||
console.log(
|
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
|
wo.envi.prodev
|
||||||
} environment`
|
} environment`
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
// }
|
// }
|
||||||
} else if ('redirectHttp2Https' === wo.envi.protocol) {
|
} else if ('redirectHttp2Https' === wo.envi.protocol) {
|
||||||
webServer = require('http')
|
portHttp = 80
|
||||||
.createServer(
|
webServer = server.all('*', function (ask, reply) {
|
||||||
server.all('*', function (ask, reply) {
|
reply.redirect(301, `https://${ask.headers.host.replace(`:${portHttp}`, `:${portHttps}`)}${ask.url}`)
|
||||||
reply.redirect(`https://${wo.envi.host}`)
|
})
|
||||||
})
|
.listen(portHttp, function (err) {
|
||||||
// 或者 require('redirect-https')() // https://www.npmjs.com/package/redirect-https
|
if (err) console.log(err)
|
||||||
)
|
else
|
||||||
.listen(portHttp, function (err) {
|
console.log(
|
||||||
if (err) console.log(err)
|
`[${new Date().toJSON()}] Server listening on ${wo.envi.protocol}://${wo.envi.host}:${portHttp} with IPv4=${ipv4} for ${wo.envi.prodev} environment`
|
||||||
else
|
)
|
||||||
console.log(
|
})
|
||||||
`[${new Date().toJSON()}] Server listening on ${wo.envi.protocol}://${wo.envi.host}:${portHttp} with IPv4=${ipv4} for ${wo.envi.prodev} environment`
|
|
||||||
)
|
|
||||||
})
|
|
||||||
}else if ('proxyHttps2Http' === wo.envi.protocol) {
|
}else if ('proxyHttps2Http' === wo.envi.protocol) {
|
||||||
var proxy=require('http-proxy').createProxyServer({
|
var proxy=require('http-proxy').createProxyServer({
|
||||||
ssl: {
|
ssl: {
|
||||||
|
Loading…
Reference in New Issue
Block a user