ruby-on-rails - Heroku 错误代码=H27 desc ="Client Request Interrupted"方法=POST USING RAILS 服务器端,Vue 前端

标签 ruby-on-rails heroku vuejs2 ruby-on-rails-5

经过几天的日志挖掘、更改存储库和很多挫折之后。 我正在使用 Heroku 上托管的 Rails api,vue 前端应用程序也托管在 Heroku 上。

在验证从 vue 到 Rails 的 post 请求时,会发生错误。 我读过这篇文章 -

Client Request Interrupted in Heroku

以及所有其他相关文章,但我还没有看到任何具体答案

this.$http.post('/authenticate',{'email':this.user.email,'password':this.user.password},{headers:
    {'Access-Control-Allow-Origin': '*'}}
  ).then((result)=>{
    localStorage.setItem('Authorization',result.data.auth_token);
    this.$http.defaults.headers.common['Authorization'] = localStorage.Authorization;
    this.$router.push('/');
  })
  .catch(error => {
    console.log(error.response);
    alert("Wrong cradentials, if you dont have an account - sign in");
  });

sock=client at=warning code=H27 desc="Client Request Interrupted" method=POST path="/authenticate" host=api-url request_id=9c3016cd-910a-4sd1f-9020-e0asd280e8 fwd="ip" dyno=web.1 connect=2ms service=289ms status=499 bytes= protocol=https

有时请求会成功到达并且一切正常,有时则不然。 约50\50...

如果我登录然后注销,然后再次登录,大多数情况下都会出现问题。 有时它会在第一次尝试时立即发生,而在第二次尝试时效果很好。 我尝试更改发送的参数,尝试了所有字符串插值变化,但没有成功。

在使用用户凭据发送 post 请求后进行关联 Rails 运行身份验证方法,该方法确认用户并将身份验证 token 作为字符串发送回。

最佳答案

原因-服务器端多个请求发生冲突。 显然我忘记阻止提交按钮的默认操作。因此,当 Js 发送 ajax 请求时,提交按钮所在的表单会发送它自己的请求。 现在是延迟问题,当js请求先到来时,它被表单请求中断了。

关于ruby-on-rails - Heroku 错误代码=H27 desc ="Client Request Interrupted"方法=POST USING RAILS 服务器端,Vue 前端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52765108/

相关文章:

ruby-on-rails - 在 rspec 测试中只需要 ActiveModel::Validations

ruby-on-rails - Ruby/Rails是否具有++等效项?

heroku - git push heroku master 给出错误 ssh : connect to host heroku. com 端口 22:连接被拒绝

vue.js - Vue 数组到表的问题

laravel - 如何在自定义的Laravel Nova工具中使用确认对话框?

ruby-on-rails - Rails after_commit?

ruby-on-rails - 如何知道要拯救哪些异常?

ruby-on-rails - 尝试将 Heroku 数据库下载到本地 : Connection to Database Failed

ruby-on-rails-3 - ruby -heroku : command not found

vue.js - 将 v-html 渲染为 VUE 组件