4

I wrote a reverse proxy for my website to serve as a load balancer. I wrote it with Node, using the nodejitsu hppt-proxy. My site is an AngularJS app that uses a websocket connection to fetch data from the server. The http-server is a node Express app. Everything works fine.

My problems started when I looked at how Google indexes my site. I couldn't get Google to see my content. All I could see was the index.html-file with no view. So I decided to use node Prerender and render the html for Google-bot on the server side.

The problem is that I can't make the websocket connection from Prerender/PhantomJS work with my proxy. When I use curl to send a request to the proxy with a url ending in '?_escaped_fragment=' as a seach bot would, I can see that the proxy sends the request to my http server which in turn sends it to Prerender. I can see from the Prerender/PhantomJS console that my Angular app works fine, and tries to open a websocket connection. That request finds its way to my proxy and the proxy recognizes it as a connection upgrade event. But for some reason proxying it doesn't work. I get nothing on my http server. All of the other stuff loads fine (index.html, static resources) but the http server doesn't get the websocket connection request.

Any idea as to what is causing the problem or how to debug it? Is there a known issue with the http-proxy module and websockets?

When i use curl to send a request with a url ending in '?_escaped_fragment=' directly to my Express.js http server's port, it works but again, a request sent to the proxy on port 80 results in everything hanging and Prerender/PhantomJS timing out. No errors but everything just hangs.

I logged the websocket requests in my proxy and stared at them for like an hour trying to compare websocket requests that work (accessing my angular app from Chrome) with ones that didn't, that is to say the Prerender/PhantomJS request. Didn't see anything obvious, but it doesn't mean there isn't anything. I don't really understand the properties of those requests.

You can find my server code here. The reverse proxy is "proxy.js", the Express http server is "server.js", and the websocket connection module for that server is "websockets.js".

Any ideas would be very welcome. I tinkered the whole day yesterday with this and no success...

hubbabubba
  • 937
  • 1
  • 9
  • 17

0 Answers0