0

Here is my html:

<!DOCTYPE html>
<html>
<head>
<link rel='stylesheet' href='css/main.css' />
</head>
<body>
<div id='container'>    
    <div id='videos'>
        <video id="localVideo" autoplay="true" ></video>
        <video id="remoteVideo" autoplay="true" ></video>
    </div>
</div>      
<script src='http://127.0.0.1:2013/socket.io/socket.io.js'></script>
<script src='adapter.js'></script>
<script src='main.js'></script>
</body>
</html>

and here is my nodejs script:

var static = require('node-static');
var http = require('http');
var file = new(static.Server)();
var app = http.createServer(function (req, res) {
  file.serve(req, res);
}).listen(2013);

var io = require('socket.io').listen(app);
io.sockets.on('connection', function (socket){
    socket.on('message', function (message) {
        socket.broadcast.emit('message', message);
    });

    socket.on('create or join', function (room) {
        var numClients = io.sockets.clients(room).length;
        if (numClients == 0){
            socket.join(room);
            socket.emit('created', room);
        } else if (numClients == 1) {
            io.sockets.in(room).emit('join', room);
            socket.join(room);
            socket.emit('joined', room);
        } else { 
            socket.emit('full', room);
        }    
    });
});

When I access my application with:

http://127.0.0.1:2013/ : works !

http://127.0.0.1/chat/ : gives mes an error:

GET http://127.0.0.1/socket.io/1/?t=1397595935052 404 (Not Found) socket.io.js:1659

My goal is to use Apache and not nodejs as http server.

yarek
  • 11,278
  • 30
  • 120
  • 219
  • Take a look at this question: http://stackoverflow.com/a/18604082/1500501 I'd say you still want to run a node HTTP server anyways (on some port) and have apache forward requests to some `/chat/` context to that port. I'm not sure of any popular way to run a node webserver without the http module (If there is a way, it surely goes against everything node). – Michael Tang Apr 15 '14 at 21:11

1 Answers1

0

An arguably better approach, that should address your concern, is to use a reverse proxy. I think Apache can be configured as a reverse proxy but many people just use NGINX in front of everything else.

NGINX is a reverse proxy first and makes easy work of proxying specific http (and https) requests (by their url) to other local ports, so you can have several disparate servers (e.g. a php site with some nodejs services for more DIRTY tasks) presented seamlessly to web users, and everything can come in on ports 80 and 443.

nginx also works a a basic web server if you just need a static host.

Adam Tolley
  • 925
  • 1
  • 12
  • 22