【问题标题】:Ajax request to other websites don't work at heroku [closed]对其他网站的 Ajax 请求在 heroku 上不起作用 [关闭]
【发布时间】:2013-03-31 21:58:06
【问题描述】:

我有一个 Rails 应用程序,当用户单击按钮时,它会向其他网站发出 ajax 请求。在 localhost 上它工作得很好,但在 heroku 它没有。它返回"We're sorry, but something went wrong." (500),这里是日志

Processing by HomeController#some_request as */*
2013-04-09T12:42:33.050720+00:00 app[web.1]:   Parameters: {"q"=>"another_web_site.com"}
2013-04-09T12:42:33.048011+00:00 app[web.1]: Started POST "/ajax/some_request" for 180.183.158.162 at 2013-04-09 12:42:33 +0000
2013-04-09T12:42:29.793791+00:00 heroku[router]: at=info method=GET path=/assets/application.js host=my_host.org fwd="180.183.158.162" dyno=web.1 connect=1ms service=5ms status=304 bytes=0
2013-04-09T12:42:54.057280+00:00 app[web.1]: 
2013-04-09T12:42:54.057280+00:00 app[web.1]: Errno::ETIMEDOUT (Connection timed out - connect(2)):
2013-04-09T12:42:54.057280+00:00 app[web.1]: 
2013-04-09T12:42:54.057280+00:00 app[web.1]: 
2013-04-09T12:42:54.057280+00:00 app[web.1]:   lib/domain_info.rb:14:in `who_is'
2013-04-09T12:42:54.057280+00:00 app[web.1]:   app/controllers/home_controller.rb:8:in `who_is'
2013-04-09T12:42:54.055802+00:00 app[web.1]: Completed 500 Internal Server Error in 21004ms
2013-04-09T12:42:54.059787+00:00 heroku[router]: at=info method=POST path=/ajax/some_request host=my_host.org fwd="180.183.158.162" dyno=web.1 connect=2ms service=21017ms status=500 bytes=643

现在超时了。昨天是https://devcenter.heroku.com/articles/error-codes#h18-request-interrupted,其中sock field 等于client

为什么会这样?

【问题讨论】:

  • 据我了解,ajax 调用是浏览器和other web site 之间的连接。那么为什么你认为 heroku 在这里很重要?
  • 网站工作正常,但 ajax 调用不工作。

标签: ruby-on-rails ruby ajax heroku


【解决方案1】:

无论您的应用在 lib/domain_info.rb 中执行的操作是否超时 - 您确定代码在您的机器/本地主机以外的位置有效吗?这段代码在做什么?分享会很有帮助。

【讨论】:

  • 为什么它不能工作?我没有检查,但应该检查。
  • 我不知道 - 你必须分享那个 domain_info 代码让我们了解它正在尝试做什么,然后想想为什么它在 Heroku 中不起作用。跨度>
  • 它只是发送http请求,没有别的。
  • 嗯,HTTP 请求超时 - 这就是导致 500 的原因。
猜你喜欢
  • 2013-05-22
  • 2016-07-20
  • 1970-01-01
  • 2011-06-18
  • 1970-01-01
  • 2021-09-23
  • 1970-01-01
  • 2018-12-12
  • 1970-01-01
相关资源
最近更新 更多