我在Rails 5.0.0上创建了一个项目。
此外,我做了与该视频完全相同的操作:https://www.youtube.com/watch?v=n0WUjGkDFS0
生成的通道除外。我生成了两个渠道:聊天和评论。
我也并行阅读了它:https://github.com/rails/rails/tree/master/actioncable
在routes.rb中,我添加了这一行:
mount ActionCable.server => '/cable'
在application.rb中,我添加了这一行:
config.action_cable.mount_path = '/cable'
结果,我运行了以下命令的项目:
rails server -b SERVER_IP -p 3020
此错误显示在控制台浏览器中:
与"ws://site.com/cable"的 WebSocket 连接失败:意外响应代码: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://*/]