编程语言
首页 > 编程语言> > ruby-on-rails-与’ws://example.com/cable’的WebSocket连接失败:意外的响应代码:404

ruby-on-rails-与’ws://example.com/cable’的WebSocket连接失败:意外的响应代码:404

作者:互联网

我在Rails 5.0.0上创建了一个项目.

此外,我所做的与本视频完全相同:https://www.youtube.com/watch?v=n0WUjGkDFS0

除了生成的通道.我生成了两个渠道:聊天和评论.

我也同时阅读:https://github.com/rails/rails/tree/master/actioncable

在routes.rb中,我添加了以下行:

挂载ActionCable.server => ‘/电缆’

在application.rb中,我添加了以下行:

config.action_cable.mount_path =’/电缆’

结果,我运行了此命令的项目:

rails服务器-b SERVER_IP -p 3020

此错误显示在控制台浏览器中:

WebSocket connection to ‘ws://site.com/cable’ failed: Unexpected response code: 404

通过运行项目的一部分日志:

Started GET "/cable" for SERVER_IP at 2016-07-12 16:20:14 +0300
Cannot render console from SERVER_IP! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
Started GET "/cable/" [WebSocket] for SERVER_IP at 2016-07-12 16:20:14 +0300
Request origin not allowed: example.com
Failed to upgrade to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: upgrade, HTTP_UPGRADE: websocket)
Finished "/cable/" [WebSocket] for SERVER_IP at 2016-07-12 16:20:14 +0300

错误可能是什么?我究竟做错了什么?

定义:

> SERVER_IP-这掩盖了服务器的原始IP地址.
> example.com-这掩盖了网站的原始URL.

解决方法:

确保已在development.rb文件中添加了这些行

config.action_cable.url = "ws://localhost:3000/cable"

config.action_cable.allowed_request_origins = [/http:\/\/*/, 
/https:\/\/*/]

标签:actioncable,nginx,ruby-on-rails-5,websocket,ruby-on-rails
来源: https://codeday.me/bug/20191118/2028037.html