[英]node-http-proxy socket.io websocket connection
I'm trying to get node-http-proxy with socket.io to work, but it always falls back to xhr, websockets won't work, although I'm connecting to the upgrade event as described in the node-http-proxy docs. 我正在尝试使socket.io的node-http-proxy正常工作,但是它总是退回到xhr,websockets无法正常工作,尽管我正在按照node-http-proxy的说明连接到升级事件。文档。
var httpProxy = require ("http-proxy");
var server = httpProxy.createServer (function (req, res, proxy) {
var buffer = httpProxy.buffer (req);
proxy.proxyRequest (req, res, {
host : "localhost",
port : 8001,
buffer : buffer
});
});
server.listen (80);
server.on('upgrade', function (req, socket, head) {
server.proxy.proxyWebSocketRequest(req, socket, head, { host : "localhost", port : 8001 });
});
The app obviously runs on localhost:8001 and if I allow all transport methods it will work fine as it uses xhrs. 该应用程序显然在localhost:8001上运行,如果我允许所有传输方法,它将使用xhrs正常运行。 If I force it to use websockets firefox will say
如果我强迫它使用websockets,Firefox会说
Firefox can't establish a connection to the server at ws://localhost/socket.io/1/websocket/cNp5J80KAWkXqjE6OZOt. @ http://localhost/socket.io/socket.io.js:2371
Just using the default method 仅使用默认方法
httpProxy.createServer (8001, "localhost").listen (80);
results in the same error. 导致相同的错误。
Proxying websockets with node-http-proxy seems to be broken on Node 0.10. 使用node-http-proxy代理websocket似乎在节点0.10上已损坏。 Here's a pull request that tries to fix it, but see my comments: the fix doesn't fully work either.
这是一个尝试修复它的请求请求,但请参见我的评论:该修复程序也不完全起作用。
https://github.com/nodejitsu/node-http-proxy/pull/402 https://github.com/nodejitsu/node-http-proxy/pull/402
I am currently using the (latest? v1.0.1) node-http-proxy and i found Websockets were indeed working reliably after a tweak (see below) on Node v0.10.20. 我当前正在使用(最新版本v1.0.1)node-http-proxy,我发现在对Node v0.10.20进行调整(参见下文)后,Websockets确实确实能够可靠地工作。 By default, node-http-proxy seems to support xhr-polling, while dropping websocket connections.
默认情况下,当删除websocket连接时,node-http-proxy似乎支持xhr-polling。
In the ' examples ', i added the 'ws' flag true 在“ 示例 ”中,我添加了“ ws”标志true
var http = require('http'),
httpProxy = require('../../lib/http-proxy');
httpProxy.createServer({
target:'http://somehost.tld:5000',
ws : true //added Websockets Flag TRUE
}).listen(80);//arbitrary port
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.