我在Rails 5.0.0上创建了一个项目。接下来我做了和这个视频里一模一样的事情:https://www.youtube.com/watch?v=n0WUjGkDFS0。除了生成的频道外,我还生成了两个频道:chat和comment。我也同时阅读了此文档: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
。浏览器控制台中出现了以下错误:一部分运行该项目的日志如下:WebSocket连接到'ws://site.com/cable'失败:意外响应代码: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
替换为您正在运行的环境):https://dev59.com/RlsW5IYBdhLWcg3wQVb2#35442353 - D-sideconfig.action_cable.allowed_request_origins = ['http:// site.com']
。 - Colibriproduction.rb
,但您可能更清楚。(不排除某个地方存在错误的可能性) - D-side