0
我想通過http-proxy代理websockets,我可以登錄接收數據,但是我無法從代理獲取發送數據。我能怎麼做 ?如何通過節點http-proxy登錄websocket流量數據
#!/usr/bin/env node
var wstarget = 'ws://localhost:8080/?r='+(Date.now()/1000 | 0);
var httpProxy = require('http-proxy');
var http = require('http');
var proxy = httpProxy.createProxyServer({});
proxy.on('open', function (proxySocket) {
proxySocket.on('data', function (data) {
//console.log('\n'+data);
console.log('',data); // Just log the receive data! Can't get the Send data?
});
});
var server = http.createServer();
server.on('upgrade', function (req, socket, head) {
console.log("Proxying websocket connection to "+wstarget);
proxy.ws(req, socket, head, {
target: wstarget,
changeOrigin: true,
ws: true});
});
server.listen(8881);