I want to pass /n/ requests to node.js and then leave everything else to Apache which is on port 8080. The proxy is running at port 80, and the code for /n/ is at port 9000.
However, node stuff like socket.io
is broken because I don't think it is proxied correctly - the socket.io query returns a 404 from apache like expected:
404 Not Found
The requested URL /socket.io/socket.io.js was not found on this server.
My starting HTML code for /n/:
<!DOCTYPE html>
<html>
<head>
<script src="/socket.io/socket.io.js"></script>
The proxy:
var app = require('http').createServer(handler);
var io = require('socket.io').listen(app);
var fs = require('fs');
var url = require('url');
var httpProxy = require('http-proxy');
io.set('log level', 1);
app.listen(9000);
httpProxy.createServer({
router: {
'localhost/n': '127.0.0.1:9000',
'localhost': '127.0.0.1:8080'
}
}).listen(80);
How can I get the proxy to pass socket.io/socket.io.js
through Node, and not Apache? I have tried using the same code that serves my static files (eg css/js), but it seems that there is no actual folder called socket.io
that exists - node seems to rewrite that.
node.js alone will not do what apache will do out of box, to serve static file. so every url/request/file need to be specify in the router. to get it running quickly you can read express for node.js here or just put specify the file in router
router: {
'localhost/n': '127.0.0.1:9000',
'localhost': '127.0.0.1:8080',
'/socket.io/socket.io.js': 'path/to/the/file'
}