Rails: Faye works for me, but still gives some JS error in the console for some unknown reason, Should I be worried?
This was an issue with my application also, heroku has a timeout of 30 and if the faye.ru/config.ru has timeout set more than 30 this error would come. try reducing it to 25 or something.faye_server = Faye::RackAdapter.new(:mount => '/faye', :timeout => 25)
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.
- Step 1 :
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' endend
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
.