Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebSocket connection to 'ws://example.com/cable' failed: Unexpected response code: 404

I created a project on Rails 5.0.0.

Further I did absolutely the same as in this video: https://www.youtube.com/watch?v=n0WUjGkDFS0

Except for the generated channels. I generated two channels: chat and comment.

I also read it in parallel: https://github.com/rails/rails/tree/master/actioncable

In routes.rb I added this line:

mount ActionCable.server => '/cable'

In application.rb I added this line:

config.action_cable.mount_path = '/cable'

As a result, I run a project of this command:

rails server -b SERVER_IP -p 3020

This error is displayed in the console browser:

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

A piece of the log by running the project:

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

The error may be what? What am I doing wrong?

Definitions:

  • SERVER_IP - this disguised the original IP address of the server.

  • example.com - this disguised the original URL of the site.

like image 604
Colibri Avatar asked Jul 12 '16 20:07

Colibri


1 Answers

Make sure you have added these lines in your development.rb file

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

config.action_cable.allowed_request_origins = [/http:\/\/*/, 
/https:\/\/*/]
like image 55
SreBalaji Thirumalai Avatar answered Sep 30 '22 05:09

SreBalaji Thirumalai