I'm using Private_Pub gem which is built on Faye, and I'm using a another app for the Faye which is provided by this blog the project that I found. to get Faye running on an app and my actual site on another app.
The error in FireFox console:
The connection to ws://xxxxxxxxxxx.herokuapp.com/faye was interrupted while the page was loading. Faye.js
and in Chrome:
WebSocket connection to 'ws://xxxxxxxxxxx.herokuapp.com/faye' failed: One or more reserved bits are on: reserved1 = 1, reserved2 = 0, reserved3 = 0
on the Chat (Faye) app log I get this in the log :
at=error code=H12 desc="Request timeout" method=GET path=/faye host=xxxxxxxxxxx.herokuapp.com request_id=xxxxxxxxxxx fwd="xxxxxxxxxxx" dyno=web.1 connect=31ms service=30112ms status=503 bytes=0
any suggestions: ?
I have added an after_filter
in the application_controller
as well to allow the domain request
To solve this problem, the Rails Apps
need to let each other access or let's say ping each other. In order to do that, we have to use something like CORS, to allow AJAX Request from Other Domain.
Here is a simpler way that I used to go allow method accesses article, it might sound confusing at first.
To do perform this on both sides, you need to create an actual complete app for the Faye
as well, unlike what is given on the Faye chat server Repo I've attached in my question.
In the Actual/Main App include this in your application_controller.rb
before_filter :cors_preflight_check
after_filter :cors_set_access_control_headers
#For all responses in this controller, return the CORS access control headers.
def cors_set_access_control_headers
headers['Access-Control-Allow-Origin'] = 'http://YOURFAYEAPP.com'
headers['Access-Control-Allow-Methods'] = 'POST, PUT, DELETE, GET, OPTIONS'
headers['Access-Control-Request-Method'] = 'http://YOURFAYEAPP.com'
headers['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept, Authorization'
end
# If this is a preflight OPTIONS request, then short-circuit the
# request, return only the necessary headers and return an empty
# text/plain.
def cors_preflight_check
if request.method == :options
headers['Access-Control-Allow-Origin'] = 'http://YOURFAYEAPP.com'
headers['Access-Control-Allow-Methods'] = 'POST, PUT, DELETE, GET, OPTIONS'
headers['Access-Control-Request-Method'] = 'http://YOURFAYEAPP.com'
headers['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept, Authorization'
render :text => '', :content_type => 'text/plain'
end
end
Step 2:
on the Faye app side include the same thing in the application_controller.rb
, but change the domain name to the Original/Actual/Main Rails app.
In that way, both can send and receive requests.
Don't put *
instead of the request parameter
, it's a security issue. You can cut down the methods
to only Get
and Post
.