Compare commits
22 Commits
Author | SHA1 | Date | |
---|---|---|---|
32c6d77178 | |||
2c4316d2d3 | |||
62e6387c1d | |||
7fe22e962a | |||
3f1f718308 | |||
ce94d283c1 | |||
a1c4f3c341 | |||
8087bab197 | |||
db63e7bf79 | |||
2615a0ebd4 | |||
d5d77af98d | |||
1f1bf77807 | |||
d4269d290d | |||
e05e5ede55 | |||
b6c7f13baa | |||
055d328bd0 | |||
20b9a220fc | |||
2170fe3518 | |||
04b13e53b9 | |||
f1a4fae704 | |||
5ee5147606 | |||
748c6e14e4 |
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartproxy",
|
"name": "@pushrocks/smartproxy",
|
||||||
"version": "3.0.40",
|
"version": "3.0.51",
|
||||||
"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.40',
|
version: '3.0.51',
|
||||||
description: 'a proxy for handling high workloads of proxying'
|
description: 'a proxy for handling high workloads of proxying'
|
||||||
}
|
}
|
||||||
|
@ -246,27 +246,32 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
|
|||||||
|
|
||||||
// Enable websockets
|
// Enable websockets
|
||||||
const wss = new plugins.ws.WebSocketServer({ server: this.httpsServer });
|
const wss = new plugins.ws.WebSocketServer({ server: this.httpsServer });
|
||||||
wss.on('connection', (ws: plugins.wsDefault) => {
|
wss.on('connection', (ws: plugins.wsDefault, reqArg: plugins.http.IncomingMessage) => {
|
||||||
console.log('got connection for wsc');
|
console.log(`got connection for wsc for https://${reqArg.headers.host}${reqArg.url}`);
|
||||||
let wscConnectedDeferred: plugins.smartpromise.Deferred<plugins.wsDefault>;
|
let wscConnectedDeferred: plugins.smartpromise.Deferred<plugins.wsDefault>;
|
||||||
|
|
||||||
ws.on('message', async (message) => {
|
ws.on('message', async (message) => {
|
||||||
if (!wscConnectedDeferred) {
|
if (!wscConnectedDeferred) {
|
||||||
wscConnectedDeferred = plugins.smartpromise.defer();
|
wscConnectedDeferred = plugins.smartpromise.defer();
|
||||||
const wsc = new plugins.wsDefault(this.router.routeWs(ws), {
|
let wsc: plugins.wsDefault;
|
||||||
headers: {
|
try {
|
||||||
Host: ws.url,
|
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', () => {
|
wsc.on('open', () => {
|
||||||
wscConnectedDeferred.resolve(wsc);
|
wscConnectedDeferred.resolve(wsc);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const wsc = await wscConnectedDeferred.promise;
|
const wsc = await wscConnectedDeferred.promise;
|
||||||
wsc.emit('message', message);
|
wsc.send(message);
|
||||||
wsc.on('message', (message) => {
|
wsc.on('message', (message) => {
|
||||||
ws.emit('message', message);
|
ws.send(message);
|
||||||
});
|
});
|
||||||
|
|
||||||
// handle closing
|
// handle closing
|
||||||
|
@ -21,12 +21,4 @@ export class ProxyRouter {
|
|||||||
});
|
});
|
||||||
return correspodingReverseProxyConfig;
|
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