Я пытаюсь использовать node-http-proxy для направления трафика на порт 3000 (мой сервер rails) и порт 8888 (мой сервер nodejs socket.io). Я использую node-http-proxy в качестве обратного прокси-сервера, подключенного к порту 80.
(Я просто копирую README из node-http-proxy)
var proxy = new httpProxy.HttpProxy({
target: {
host: 'localhost',
port: CONFIG.RAILS_PORT,
}
});
var server = http.createServer(function(req, res) {
//
// Proxy normal HTTP requests
//
proxy.proxyRequest(req, res);
});
server.on('upgrade', function(req, socket, head) {
//
// Proxy websocket request to another port
//
console.log('inside upgrade');
proxy.proxyWebSocketRequest(req, socket, head, {
host: 'localhost',
port: CONFIG.NODEJS_PORT
});
});
server.listen(80);
var WrappedServer = require('./wrappedServer').WrappedServer
var singleton = new WrappedServer();
singleton.run(CONFIG.NODEJS_PORT, {'log level': 2});
А это мой client.js в браузере.
var socket = io.connect('http://localhost', {'sync disconnect on unload': false});
Почему-то io.connect не может подключиться к серверу nodejs. Я получаю ответ от io.connect:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Action Controller: Exception caught</title>
<style>
body { background-color: #fff; color: #333; }
body, p, ol, ul, td {
font-family: helvetica, verdana, arial, sans-serif;
font-size: 13px;
line-height: 18px;
}
pre {
background-color: #eee;
padding: 10px;
font-size: 11px;
}
a { color: #000; }
a:visited { color: #666; }
a:hover { color: #fff; background-color:#000; }
</style>
</head>
<body>
<h1>Routing Error</h1>
<p><pre>No route matches [GET] "/socket.io/1"</pre></p>
</body>
</html>
Любая идея, как я могу заставить io.connect подключиться к серверу nodejs? Я не знаю, как я могу запустить io.connect, чтобы добраться до блока server.upgrade.
Спасибо !