Websocket header missing
Asked Answered
T

1

17

I'm using the 'faye' gem with Rails 3.2.13. In development I'm running faye on localhost:9292 and my app on localhost:3000. I'm able to activate pop-up windows with a curl request from the command line but I can't establish a connection from within my app. The error I'm getting in my console is:

WebSocket connection to 'ws://localhost:9292/faye' failed: Error during WebSocket handshake: 'Upgrade' header is missing

I am trying to define a header for faye in my application.js file:

$(function() {
  var faye = new Faye.Client("http://localhost:9292/faye");
  faye.setHeader("Access-Control-Allow-Origin", "http://localhost:3000");
  faye.subscribe('/messages', function (data) {
  alert(data);
  });
});

Is this the right way to add a Header?

I found a discussion of a similar problem here: https://github.com/faye/faye/issues/222 In this case the error seemed to be related to the ssl settings not being loaded. I checked my rack gem's lib directory and found

def ssl?
  scheme == 'https'
end

This seems fine. How do I know if the settings aren't being properly loaded?

Any clues about where to look next would be much appreciated.

Treasurehouse answered 17/8, 2013 at 7:20 Comment(1)
Was this from following a railscast? I have the same issue.Cartan
C
35

I had the same issue while following Ryan Bates's railscast: http://railscasts.com/episodes/260-messaging-with-faye

The Faye web socket server requires an adapter to run on Thin web server and send the upgrade header.

Adding this line to your Faye rackup file (.ru) will load the adapter via rack middleware:

Faye::WebSocket.load_adapter('thin')

I found this solution here: https://github.com/ryanb/private_pub/issues/39#issuecomment-4225647

Cartan answered 17/10, 2013 at 6:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.