【发布时间】:2018-08-10 18:35:57
【问题描述】:
我有一个在 GAE 灵活环境中托管的 nodejs 应用程序。我们已经设置了谷歌管理的 SSL,并且 https 路由有效。
但由于我们以静态方式为应用程序提供服务,因此我们无法强制从服务器端进行重定向(据我所知)
这是服务器代码(我从 index.js 调用 start 方法):
const express = require('express')
const PORT = process.env.PORT || 8080
/**
* Basic web server construction.
* Parameter function passed into 'start' as serverProcess
* contains the actual meat of the server side processing
* for the node.js backend
*/
class WebServer {
constructor () {
this.app = express()
this.app.use(express.static('dist/public'))
}
/**
* Begins a web server executing the 'serverProcess' function provided
* bodyParser.json() used as middleware to enable POST requests with JSON body content
* @param {Function} serverProcess The business logic function for the node.js backend as a whole
*/
start () {
return new Promise((resolve, reject) => {
try {
this.server = this.app.listen(PORT, function () {
console.log('Web server being created')
resolve()
})
} catch (e) {
console.error(e)
reject(e)
}
})
}
stop () {
return new Promise((resolve, reject) => {
try {
this.server.close(() => {
resolve()
})
} catch (e) {
console.error(e.message)
reject(e)
}
})
}
}
module.exports = WebServer
如何确保它始终重定向到 https?
我听说过 x-forwarded-proto,但我不确定它是什么以及如何实现它,而且由于它是一个灵活的环境,我不能使用 GAE 提供的处理程序。
【问题讨论】:
标签: node.js reactjs express google-app-engine https