【问题标题】:Sails.js redirects to example.com on productionSails.js 在生产环境中重定向到 example.com 【发布时间】:2018-06-18 00:11:46 【问题描述】: 在开发模式下一切正常,但在生产模式下,不知何故,帆将我重定向到https://example.com 不确定,为什么。有什么想法吗? 【问题讨论】: 标签: sails.js 【解决方案1】: 您需要将config/env/production.js 中的baseUrl 从example.com 更改为localhost:1337。在生产模式下运行时,这些设置将应用于sails 服务器。 【讨论】: 添加 localhost:1337 会导致错误(在 index.js 文件中)。添加 http://localhost:1337 会导致访问 localhost:1337 时重定向过多 【解决方案2】: 请在production.js 中设置baseUrl,不包括端口。 意思是,如果你想服务http://localhost:1337,请设置baseUrl: 'http://localhost'。 不要设置baseUrl: 'http://localhost:1337' 在自定义钩子代码中,他们比较req.hostname和url.host来决定是否调用重定向。 req.hostname 不能有端口,url.host 可以有端口,如果你用端口设置的话。 【讨论】: