Faye on Heroku: Cross Domain Issues

Currently, I have both a rails app and a faye-server app on Heroku. The fire server was cloned from here ( https://github.com/ntenisOT/Faye-Heroku-Cedar ) and seems to work correctly. I disabled websockets, as they are not supported on Heroku. Despite the claim on the Faye website that:

"Faye clients and servers transparently support cross-domain communication, so your client can connect to the server in any domain you like without further configuration."

I still encounter this error when I try to send a message to the faye channel:

    XMLHttpRequest cannot load http://MYFAYESERVER.herokuapp.com. Origin http://MYAPPURL.herokuapp.com is not allowed by Access-Control-Allow-Origin.

I read about CORS and tried to implement some of the solutions outlined here: http://www.tsheffler.com/blog/?p=428 , but still no luck. I would like to hear from someone who:

1) The rails application is installed on the Heroku server 2) Does the Faye server have a Heroku server 3) Two of them successfully communicate with each other!

Many thanks.

+5
source share
2 answers

I just got my faye and rails apps hosted on heroku, chatting for the last hour or so ... here are my observations:

  • Make sure your FAYE_TOKEN is installed on all your servers if you use the env variable.

  • Disabling the websites that you have already done ... client.disable(...)does not work for me, I used it instead Faye.Transport.WebSocket.isUsable = function(_,c) { c(false) }.

  • , ... dev, , , faye... , -, . , broadcast_server_uri application_controller.rb, , , -, .

....

class ApplicationController < ActionController::Base
  def broadcast_server
      if request.port.to_i != 80
        "http://my-faye-server.herokuapp.com:80/faye"
      else
        "http://my-faye-server.herokuapp.com/faye"
      end            
  end
  helper_method :broadcast_server

  def broadcast_message(channel, data)
    message = { :ext => {:auth_token => FAYE_TOKEN}, :channel => channel, :data => data}
    uri = URI.parse(broadcast_server)
    Net::HTTP.post_form(uri, :message => message.to_json)
  end


end

javascript,

<script>
  var broadcast_server = "<%= broadcast_server %>"
  var faye;
$(function() {
    faye = new Faye.Client(broadcast_server);
    faye.setHeader('Access-Control-Allow-Origin', '*');
    faye.connect();
    Faye.Transport.WebSocket.isUsable = function(_,c) { c(false) }

      // spin off your subscriptions here
  });
</script>

FWIW, Access-Control-Allow-Origin, , , - XMLHttpRequest cannot load http://... , , . ( ...)

+1

, Rails/Faye Heroku, Access-Control-Allow-Origin - Access-Control-Allow-Origin: your-domain.com?

Access-Control-Allow-Origin: *, ,

HTTP- Bayeux. , setHeader() , , ( ).

client.setHeader('', 'OAuth abcd-1234');

: http://faye.jcoglan.com/browser.html

, client.setHeader('Access-Control-Allow-Origin', '*');

0

All Articles