【发布时间】:2014-04-19 06:42:30
【问题描述】:
我想反向代理一个使用 websockets 的现有应用程序,但使用应用程序中间件在应用程序前面实现授权层。
node-http-proxy 宣传了这两个功能,但我似乎无法将它们结合起来。
反向代理 websockets 工作正常:
var httpProxy = require('http-proxy');
httpProxy.createProxyServer({
target: 'http://127.0.0.1:8888', // where do we want to proxy to?
ws : true // proxy websockets as well
}).listen(3000);
不过,当我查看middleware examples 时,它们似乎都对服务器使用了连接,此时 websocket 支持似乎消失了。例如。
var httpProxy = require('http-proxy'),
connect = require('connect');
var proxy = httpProxy.createProxyServer({
target: 'http://localhost:8888',
ws: true
});
connect.createServer(
connect.compress({
// Pass to connect.compress() the options
// that you need, just for show the example
// we use threshold to 1
threshold: 1
}),
function (req, res) {
proxy.web(req, res);
}
).listen(3000);
这是一个已知的限制,还是有其他方法可以结合 websocket 反向代理和中间件?
【问题讨论】:
-
你弄明白了吗?