Compare commits
14 Commits
Author | SHA1 | Date | |
---|---|---|---|
3f1f718308 | |||
ce94d283c1 | |||
a1c4f3c341 | |||
8087bab197 | |||
db63e7bf79 | |||
2615a0ebd4 | |||
d5d77af98d | |||
1f1bf77807 | |||
d4269d290d | |||
e05e5ede55 | |||
b6c7f13baa | |||
055d328bd0 | |||
20b9a220fc | |||
2170fe3518 |
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@pushrocks/smartproxy",
|
||||
"version": "3.0.42",
|
||||
"version": "3.0.49",
|
||||
"private": false,
|
||||
"description": "a proxy for handling high workloads of proxying",
|
||||
"main": "dist_ts/index.js",
|
||||
|
@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@pushrocks/smartproxy',
|
||||
version: '3.0.42',
|
||||
version: '3.0.49',
|
||||
description: 'a proxy for handling high workloads of proxying'
|
||||
}
|
||||
|
@ -246,15 +246,21 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
|
||||
|
||||
// Enable websockets
|
||||
const wss = new plugins.ws.WebSocketServer({ server: this.httpsServer });
|
||||
wss.on('connection', (ws: plugins.wsDefault, reqArg) => {
|
||||
console.log(`got connection for wsc for ${reqArg.url}`);
|
||||
wss.on('connection', (ws: plugins.wsDefault, reqArg: plugins.http.IncomingMessage) => {
|
||||
console.log(`got connection for wsc for https://${reqArg.headers.host}${reqArg.url}`);
|
||||
let wscConnectedDeferred: plugins.smartpromise.Deferred<plugins.wsDefault>;
|
||||
|
||||
ws.on('message', async (message) => {
|
||||
if (!wscConnectedDeferred) {
|
||||
wscConnectedDeferred = plugins.smartpromise.defer();
|
||||
const parsedUrl = plugins.url.parse(reqArg.url);
|
||||
const wsc = new plugins.wsDefault(`${this.router.routeWs(reqArg)}${parsedUrl.path}`);
|
||||
let wsc;
|
||||
try {
|
||||
wsc = new plugins.wsDefault(`ws://${this.router.routeReq(reqArg).destinationIp}:${this.router.routeReq(reqArg).destinationPort}${reqArg.url}`);
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
ws.terminate();
|
||||
return;
|
||||
}
|
||||
|
||||
wsc.on('open', () => {
|
||||
wscConnectedDeferred.resolve(wsc);
|
||||
|
@ -21,12 +21,4 @@ export class ProxyRouter {
|
||||
});
|
||||
return correspodingReverseProxyConfig;
|
||||
}
|
||||
|
||||
public routeWs(wsReq: plugins.http.IncomingMessage) {
|
||||
const originalHost = plugins.url.parse(wsReq.url).host;
|
||||
const correspodingReverseProxyConfig = this.reverseProxyConfigs.find((reverseConfig) => {
|
||||
return reverseConfig.hostName === originalHost;
|
||||
});
|
||||
return correspodingReverseProxyConfig.destinationIp;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user