2

I have installed node inside a folder and am forwarding it through apache. I am doing this because I have several virtualhosts run through apache, and I do not want to take the time to set up everything through node. Apache and Node.js on the Same Server

However, I am trying to create a chat engine. I try to include some js files, but they search for http://example.org/myscript.js instead of http://example.org/chat/myscript.js

I got around this by using

<base href="/chat/">

However, now I am trying to integrate socket.io. I included socket.io from https://cdn.socket.io/socket.io-1.3.5.js because I could not get the locally serverd /socket.io/socket.io.js to properly be located.

Now socket.io is trying to connect to http://example.org/socket.io That dierectory does not exist. If anything, the proper path should be http://example.org/chat/socket.io

I have been looking all over the internet for a solution. There must be something fundamental or obvious about how nodejs/express operates that I am missing. Thanks a million!

Server.js - This is the file I start with node.

var express = require('express');
var path = require('path');
var app = express();
var http = require('http').createServer(app);
var io = require('socket.io').listen(http, { log: true, resource:'/socket.io/'});

app.use('/socket.io', express.static(path.join(__dirname,'/node_modules/socket.io/lib/')));
app.use('/bootstrap', express.static(path.join(__dirname,'/node_modules/bootstrap/dist/')));
app.use('/', express.static(__dirname));


var server = app.listen(8000);

io.sockets.on('connection', function(socket) {
  console.log('A user connected!');
})
Community
  • 1
  • 1
Dr Shenanigan
  • 163
  • 2
  • 9
  • Which version of apache are you using? – pcnate May 31 '15 at 01:39
  • I am using apache 2.2.3 – Dr Shenanigan May 31 '15 at 01:43
  • 1
    apache 2.2.x does not support websockets through proxy, this does not solve your issue but it will be a hinderance. http://httpd.apache.org/docs/2.4/mod/mod_proxy_wstunnel.html – pcnate May 31 '15 at 01:50
  • **Show us your express code.** The very first thing you need to understand with node.js and express is that they don't server ANY files by default (unlike Apache). They only serve files that there is a route installed for. If you install socket.io properly, it will automatically set up a route to serve `/socket.io/socket.io.js` automatically and to handle the `/socket.io` path that initiates a webSocket connection. These are not directories. They are routes within express that leads to code and then the code knows what to do when that route is requested. – jfriend00 May 31 '15 at 05:05
  • I am sure it is a combination of the fact my server needs apache 2.4, and my server.js file. – Dr Shenanigan May 31 '15 at 05:10

0 Answers0