New Sails.js应用程序在Heroku中获得无限重定向



我用 Sails.js 版本 1.0.2 创建了一个空应用程序。我使用了"航行新"命令的"Web App"选项。在本地主机上启动时,它在开发和生产环境中都能正常工作。

接下来,我想把这个应用程序放到Heroku中。

我做了什么:

  • 在Heroku中使用"heroku创建"创建新应用程序;
  • 在我的应用程序根目录中初始化了新的 git 存储库;
  • 在我的应用程序根目录中创建了Procfile,其中包含文本:"web:npm start">
  • 更改的生产环境配置(在 \config\env\production.js 中(:
    • 将套接字.onlyAllowOrigins和custom.baseUrl值更改为"http://myappname.herokuapp.com">
    • 将 http.trustProxy 值更改为"true">
  • 使用 "heroku git:remote -a myappname" 为我的存储库设置 heroku remote
  • 添加,提交并使用"git push heroku master"将我的存储库推送到Heroku

它成功构建并带有一些警告,但最糟糕的是该应用程序无法正常工作。每个请求都会导致与 heroku[router] 重定向到同一地址的循环。

以下是Heroku日志的一部分:

2018-05-16T12:52:25.991036+00:00 app[web.1]: debug: -------------------------------------------------------
2018-05-16T12:52:25.991290+00:00 app[web.1]: debug: :: Wed May 16 2018 12:52:25 GMT+0000 (UTC)
2018-05-16T12:52:25.991366+00:00 app[web.1]: debug: Environment : production
2018-05-16T12:52:25.991441+00:00 app[web.1]: debug: Port        : 37749
2018-05-16T12:52:25.991589+00:00 app[web.1]: debug: -------------------------------------------------------
2018-05-16T12:52:26.645022+00:00 heroku[web.1]: State changed from starting to up
2018-05-16T12:52:27.762757+00:00 heroku[router]: at=info method=GET path="/" host=myappname.herokuapp.com request_id=ee575a91-305f-4518-af9f-537ceccbc3cf fwd="83.45.25.57" dyno=web.1 connect=2ms service=48ms status=302 bytes=523 protocol=https
2018-05-16T12:52:28.039174+00:00 heroku[router]: at=info method=GET path="/" host=myappname.herokuapp.com request_id=980d6e72-b03c-4704-af97-56c7f9debc8b fwd="83.45.25.57" dyno=web.1 connect=0ms service=9ms status=302 bytes=360 protocol=http
2018-05-16T12:52:28.185571+00:00 heroku[router]: at=info method=GET path="/" host=myappname.herokuapp.com request_id=b46a235f-fbf7-4404-a4b7-0a95bb1a0254 fwd="83.45.25.57" dyno=web.1 connect=1ms service=5ms status=302 bytes=360 protocol=http
2018-05-16T12:52:28.339593+00:00 heroku[router]: at=info method=GET path="/" host=myappname.herokuapp.com request_id=03bbd460-3200-4158-a555-33c20262a212 fwd="83.45.25.57" dyno=web.1 connect=2ms service=7ms status=302 bytes=360 protocol=http
2018-05-16T12:52:28.484756+00:00 heroku[router]: at=info method=GET path="/" host=myappname.herokuapp.com request_id=af7303b1-f04c-431b-93b5-9e8b148a6721 fwd="83.45.25.57" dyno=web.1 connect=1ms service=4ms status=302 bytes=360 protocol=http
2018-05-16T12:52:28.637541+00:00 heroku[router]: at=info method=GET path="/" host=myappname.herokuapp.com request_id=1535454e-58b0-41d2-821d-317d7ebabeeb fwd="83.45.25.57" dyno=web.1 connect=4ms service=8ms status=302 bytes=360 protocol=http
2018-05-16T12:52:28.788965+00:00 heroku[router]: at=info method=GET path="/" host=myappname.herokuapp.com request_id=559d3426-78b9-4b65-8063-c44eb728d825 fwd="83.45.25.57" dyno=web.1 connect=1ms service=6ms status=302 bytes=360 protocol=http
2018-05-16T12:52:28.936187+00:00 heroku[router]: at=info method=GET path="/" host=myappname.herokuapp.com request_id=e4ad129d-746b-490c-9d0d-c77966b98d46 fwd="83.45.25.57" dyno=web.1 connect=1ms service=7ms status=302 bytes=360 protocol=http
2018-05-16T12:52:29.082496+00:00 heroku[router]: at=info method=GET path="/" host=myappname.herokuapp.com request_id=92a66cab-344e-410d-9ebf-8c8bddec80bd fwd="83.45.25.57" dyno=web.1 connect=2ms service=5ms status=302 bytes=360 protocol=http
2018-05-16T12:52:29.233773+00:00 heroku[router]: at=info method=GET path="/" host=myappname.herokuapp.com request_id=92f3734c-6e37-48d6-9849-807b53f1e1f7 fwd="83.45.25.57" dyno=web.1 connect=1ms service=5ms status=302 bytes=360 protocol=http

尝试将custom.baseUrl设置为HTTP和HTTPS,没有区别。 哪里出了问题?

@marvin,你不需要在heroku中创建Procfile。 只需在部署应用时,它将自动运行并设置环境生产。

最新更新