我已经启动了一个新的 Sails.js 项目,并希望实现 Passport-twitter 进行身份验证。
一切都使用 sails-generator-auth 模块正确实现,但在 Twitter 授权后我被重定向到
http://localhost:9090/auth/twitter/callback
Sails 在 localhost:9090 上的 nginx 后面运行 - 如何覆盖主机名?
到目前为止,我尝试设置 app.set('trust proxy');在 config/env/development.js 中
http: {
customMiddleware: function(app) {
console.log('trust proxy');
app.enable('trust proxy');
}
},
我在升 sails 时看到console.log输出,但它不影响重定向。
最佳答案
答案很简单,但没有很好的记录。还有另一篇文章实际上讨论了一个略有不同的问题,但给出了正确的答案: How to get current domain address in sails.js
If you're on Sails v0.10.x, you can use sails.getBaseurl() to get the full protocol, domain and port that your app is being served from. Starting with Sails v0.10.0-rc6, this also checks the sails.config.proxyHost and sails.config.proxyPort, which you can set manually in your one of your config files (like config/local.js) if your app is being served via a proxy (e.g. if it's deployed on Modulus.io, or proxied through an Nginx server).
将 sails 实例配置为 localhost:9090 是正确的,但如果您想更改代理后面的主机名/端口,则必须配置 proxyHost
和 proxyPort
- 这可以在任何地方完成,但最适合 local.js
关于nginx - Sails.js + Nginx 代理后面的通行证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26358291/