Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing socket.io with nodejs on a server with apache as a reverse proxy
    primarykey
    data
    text
    <p>I'm attempting to use Node.js with Socket.IO to faciliate messaging between the browser and client, following <a href="http://socket.io/#how-to-use" rel="noreferrer">the guide</a>.</p> <p>However, I had to setup Node reverse-proxied behind Apache. So, instead of example.com:8080 for node, I'm using example.com/nodejs/.</p> <p>This seems to cause Socket.IO to lose sense of itself. Here's my node app</p> <pre><code>var io = require('socket.io').listen(8080); // this has to be here, otherwise the client tries to // send events to example.com/socket.io instead of example.com/nodejs/socket.io io.set( 'resource', '/nodejs/socket.io' ); io.sockets.on('connection', function (socket) { socket.emit('bar', { one: '1'}); socket.on('foo', function( data ) { console.log( data ); }); }); </code></pre> <p>And here's what my client file looks like</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta charset=utf-8 /&gt; &lt;title&gt;Socket.IO test&lt;/title&gt; &lt;script src="http://example.com/nodejs/socket.io/socket.io.js"&gt;&lt;/script&gt; &lt;script&gt; var socket = io.connect('http://example.com/nodejs/'); console.log( socket ); socket.on( 'bar', function (data) { console.log(data); socket.emit( 'foo', {bar:'baz'} ); }); socket.emit('foo',{bar:'baz'}); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;p id="hello"&gt;Hello World&lt;/p&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>The problem here is the script reference to <a href="http://example.com/nodejs/socket.io/socket.io.js" rel="noreferrer">http://example.com/nodejs/socket.io/socket.io.js</a>. It doesn't return the expected javasscript content - instead it returns "Welcome to socket.io" as if I hit <a href="http://example.com/nodejs/" rel="noreferrer">http://example.com/nodejs/</a>.</p> <p>Any idea how I can make this work?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload