relative path for websockets

6k Views Asked by At

I have installed Apache2.2.22 and nodejs 0.10.12 succesfully in windows server 2012 r2.

I succesfully made node a windows service, using nssm, so it will always run.

Node "lives" in 8000 port and I have installed a proxy in apache's httpd.conf like so

ProxyPass /nodejs http://localhost:8000
ProxyPassReverse /nodejs http://localhost:8000

When I check my site in server's browser, websockets work fine.

When I check my site in my laptops browser, I get error.

I guess its caused because I create websockets like so

 var ci = new WebSocket("ws://localhost:8000");

That's why works on server,not on my laptop. Because of the localhost. First, am I right?

Second. The only problem is, I dont know how to create relative paths for websockets. I have tried different syntaxes, but no luck. Please, can somebody show me how, and explain to me?

Thanks in advance.

EDIT : I did not set up windows server 2012 r2. A collegue did. I just uploaded the website. I made an Inbound rule in Windows Firewall, so port 8000 is open. Also ,one for port 80 (for Apache). I tried stuff like robertklep suggests, no luck. Maybe an issue of OS? (security restrictions?)

Inside httpd.conf I also have

 ProxyPass /geoserver http://localhost:8080/geoserver
 ProxyPassReverse /geoserver http://localhost:8080/geoserver

Its before the node's proxy. Its about Geoserver and port 8080, which also has an inbound rule. Works just fine.

Node only works locally (having localhost in the URL). Locally, if I remove the Proxy lines from httpd.conf, still works.

I have no clue, how to install/configure the proxy_wstunnel_module. And I am not sure if I need it.

I did everything in my powers, please advice

Thanks

1

There are 1 best solutions below

7
On

First: yes, you are right.

Second: I think WebSocket URL's always have to be absolute. To determine that URL dynamically, you can use something like this:

var ci = new WebSocket('ws://' + location.hostname + ':8000');

I'm assuming that you're not using the Node server on port 8000 to also serve the HTML files. If you are, this might also work (and is a bit shorter):

var ci = new WebSocket('ws://' + location.host);