Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
b5c83b5c75 | |||
63ce1a44a4 | |||
759f70b84d | |||
45ce56b118 |
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartproxy",
|
"name": "@pushrocks/smartproxy",
|
||||||
"version": "3.0.52",
|
"version": "3.0.54",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "a proxy for handling high workloads of proxying",
|
"description": "a proxy for handling high workloads of proxying",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
|
@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@pushrocks/smartproxy',
|
name: '@pushrocks/smartproxy',
|
||||||
version: '3.0.52',
|
version: '3.0.54',
|
||||||
description: 'a proxy for handling high workloads of proxying'
|
description: 'a proxy for handling high workloads of proxying'
|
||||||
}
|
}
|
||||||
|
@ -245,48 +245,33 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Enable websockets
|
// Enable websockets
|
||||||
const wss = new plugins.ws.WebSocketServer({ server: this.httpsServer });
|
const wsServer = new plugins.ws.WebSocketServer({ server: this.httpsServer });
|
||||||
wss.on('connection', (ws: plugins.wsDefault, reqArg: plugins.http.IncomingMessage) => {
|
wsServer.on('connection', async (wsIncoming: plugins.wsDefault, reqArg: plugins.http.IncomingMessage) => {
|
||||||
console.log(`wss: got connection for wsc for https://${reqArg.headers.host}${reqArg.url}`);
|
console.log(`wss: got connection for wsc for https://${reqArg.headers.host}${reqArg.url}`);
|
||||||
let wscConnectedDeferred: plugins.smartpromise.Deferred<plugins.wsDefault>;
|
|
||||||
|
let wsOutgoing: plugins.wsDefault;
|
||||||
|
try {
|
||||||
|
wsOutgoing = new plugins.wsDefault(`ws://${this.router.routeReq(reqArg).destinationIp}:${this.router.routeReq(reqArg).destinationPort}${reqArg.url}`);
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err);
|
||||||
|
wsIncoming.terminate();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ws.on('message', async (message) => {
|
wsIncoming.on("message", (message, isBinary) => {
|
||||||
if (!wscConnectedDeferred) {
|
console.log("client to upstream", message);
|
||||||
wscConnectedDeferred = plugins.smartpromise.defer();
|
wsOutgoing.send(message, { binary: isBinary });
|
||||||
let wsc: plugins.wsDefault;
|
|
||||||
try {
|
|
||||||
wsc = new plugins.wsDefault(`ws://${this.router.routeReq(reqArg).destinationIp}:${this.router.routeReq(reqArg).destinationPort}${reqArg.url}`, {
|
|
||||||
headers: reqArg.headers
|
|
||||||
});
|
|
||||||
} catch (err) {
|
|
||||||
console.log(err);
|
|
||||||
ws.terminate();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
wsc.on('open', () => {
|
|
||||||
console.log('wsc opened.');
|
|
||||||
wscConnectedDeferred.resolve(wsc);
|
|
||||||
});
|
|
||||||
wsc.on('message', (message) => {
|
|
||||||
ws.send(message);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
const wsc = await wscConnectedDeferred.promise;
|
|
||||||
wsc.send(message);
|
|
||||||
// handle closing
|
|
||||||
const cleanUp = () => {
|
|
||||||
ws.terminate();
|
|
||||||
wsc.terminate();
|
|
||||||
};
|
|
||||||
|
|
||||||
ws.on('close', (message) => {
|
|
||||||
cleanUp();
|
|
||||||
});
|
|
||||||
|
|
||||||
wsc.on('close', (message) => {
|
|
||||||
cleanUp();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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 = 600 * 1000;
|
this.httpsServer.keepAliveTimeout = 600 * 1000;
|
||||||
this.httpsServer.headersTimeout = 600 * 1000;
|
this.httpsServer.headersTimeout = 600 * 1000;
|
||||||
|
Reference in New Issue
Block a user