Compare commits
36 Commits
Author | SHA1 | Date | |
---|---|---|---|
ee4f7fc48d | |||
f6e656361b | |||
e51c2a88cc | |||
7f8112930d | |||
b5c83b5c75 | |||
63ce1a44a4 | |||
759f70b84d | |||
45ce56b118 | |||
0cc7184e58 | |||
392e241208 | |||
32c6d77178 | |||
2c4316d2d3 | |||
62e6387c1d | |||
7fe22e962a | |||
3f1f718308 | |||
ce94d283c1 | |||
a1c4f3c341 | |||
8087bab197 | |||
db63e7bf79 | |||
2615a0ebd4 | |||
d5d77af98d | |||
1f1bf77807 | |||
d4269d290d | |||
e05e5ede55 | |||
b6c7f13baa | |||
055d328bd0 | |||
20b9a220fc | |||
2170fe3518 | |||
04b13e53b9 | |||
f1a4fae704 | |||
5ee5147606 | |||
748c6e14e4 | |||
f018957de4 | |||
a6583b037c | |||
3ab4144c9a | |||
0d2885ace4 |
13680
package-lock.json
generated
13680
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@pushrocks/smartproxy",
|
||||
"version": "3.0.38",
|
||||
"version": "3.0.56",
|
||||
"private": false,
|
||||
"description": "a proxy for handling high workloads of proxying",
|
||||
"main": "dist_ts/index.js",
|
||||
@ -16,9 +16,10 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@gitzone/tsbuild": "^2.1.65",
|
||||
"@gitzone/tsrun": "^1.2.39",
|
||||
"@gitzone/tstest": "^1.0.73",
|
||||
"@pushrocks/tapbundle": "^5.0.4",
|
||||
"@types/node": "^18.6.4"
|
||||
"@types/node": "^18.7.8"
|
||||
},
|
||||
"dependencies": {
|
||||
"@pushrocks/lik": "^6.0.0",
|
||||
@ -26,7 +27,7 @@
|
||||
"@pushrocks/smartpromise": "^3.1.7",
|
||||
"@pushrocks/smartrequest": "^2.0.10",
|
||||
"@pushrocks/smartstring": "^4.0.2",
|
||||
"@tsclass/tsclass": "^4.0.17",
|
||||
"@tsclass/tsclass": "^4.0.19",
|
||||
"@types/ws": "^8.5.3",
|
||||
"ws": "^8.8.1"
|
||||
},
|
||||
|
4341
pnpm-lock.yaml
generated
Normal file
4341
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@pushrocks/smartproxy',
|
||||
version: '3.0.38',
|
||||
version: '3.0.56',
|
||||
description: 'a proxy for handling high workloads of proxying'
|
||||
}
|
||||
|
@ -245,47 +245,37 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
|
||||
);
|
||||
|
||||
// Enable websockets
|
||||
const wss = new plugins.ws.WebSocketServer({ server: this.httpsServer });
|
||||
wss.on('connection', (ws: plugins.wsDefault) => {
|
||||
console.log('got connection for wsc');
|
||||
let wscConnectedDeferred: plugins.smartpromise.Deferred<plugins.wsDefault>;
|
||||
const wsServer = new plugins.ws.WebSocketServer({ server: this.httpsServer });
|
||||
wsServer.on('connection', async (wsIncoming: plugins.wsDefault, reqArg: plugins.http.IncomingMessage) => {
|
||||
console.log(`wss proxy: got connection for wsc for https://${reqArg.headers.host}${reqArg.url}`);
|
||||
|
||||
let wsOutgoing: plugins.wsDefault;
|
||||
try {
|
||||
wsOutgoing = new plugins.wsDefault(`ws://${this.router.routeReq(reqArg).destinationIp}:${this.router.routeReq(reqArg).destinationPort}${reqArg.url}`);
|
||||
console.log('wss proxy: initiated outgoing proxy')
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
wsIncoming.terminate();
|
||||
return;
|
||||
}
|
||||
|
||||
ws.on('message', async (message) => {
|
||||
if (!wscConnectedDeferred) {
|
||||
wscConnectedDeferred = plugins.smartpromise.defer();
|
||||
const wsc = new plugins.wsDefault(this.router.routeWs(ws), {
|
||||
headers: {
|
||||
Host: ws.url,
|
||||
},
|
||||
});
|
||||
|
||||
wsc.on('open', () => {
|
||||
wscConnectedDeferred.resolve(wsc);
|
||||
});
|
||||
}
|
||||
const wsc = await wscConnectedDeferred.promise;
|
||||
wsc.emit('message', message);
|
||||
wsc.on('message', (message) => {
|
||||
ws.emit('message', message);
|
||||
});
|
||||
|
||||
// handle closing
|
||||
const cleanUp = () => {
|
||||
ws.terminate();
|
||||
wsc.terminate();
|
||||
};
|
||||
|
||||
ws.on('close', (message) => {
|
||||
cleanUp();
|
||||
});
|
||||
|
||||
wsc.on('close', (message) => {
|
||||
cleanUp();
|
||||
});
|
||||
wsIncoming.on("message", (message, isBinary) => {
|
||||
// console.log("client to upstream", message);
|
||||
wsOutgoing.send(message, { binary: isBinary });
|
||||
});
|
||||
|
||||
wsOutgoing.on("message", (message, isBinary) => {
|
||||
// console.log("upstream to client", message);
|
||||
wsIncoming.send(message, { binary: isBinary });
|
||||
});
|
||||
wsIncoming.on("error", () => wsOutgoing.terminate());
|
||||
wsOutgoing.on("error", () => wsIncoming.terminate());
|
||||
wsIncoming.on("close", () => wsOutgoing.terminate());
|
||||
wsOutgoing.on("close", () => wsIncoming.terminate());
|
||||
|
||||
});
|
||||
this.httpsServer.keepAliveTimeout = 61000;
|
||||
this.httpsServer.headersTimeout = 65000;
|
||||
this.httpsServer.keepAliveTimeout = 600 * 1000;
|
||||
this.httpsServer.headersTimeout = 600 * 1000;
|
||||
|
||||
this.httpsServer.on('connection', (connection: plugins.net.Socket) => {
|
||||
this.socketMap.add(connection);
|
||||
|
@ -21,12 +21,4 @@ export class ProxyRouter {
|
||||
});
|
||||
return correspodingReverseProxyConfig;
|
||||
}
|
||||
|
||||
public routeWs(ws: plugins.wsDefault) {
|
||||
const originalHost = plugins.url.parse(ws.url).host;
|
||||
const correspodingReverseProxyConfig = this.reverseProxyConfigs.find((reverseConfig) => {
|
||||
return reverseConfig.hostName === originalHost;
|
||||
});
|
||||
return correspodingReverseProxyConfig.destinationIp;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user