fix(websockets): now proxying websockets as well
This commit is contained in:
parent
2c55a6b819
commit
07a8d9bec6
@ -126,15 +126,17 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
const Websocket = await import('ws');
|
|
||||||
|
|
||||||
// Enable websockets
|
// Enable websockets
|
||||||
const wss = new plugins.ws.Server({ server: this.httpsServer });
|
const wss = new plugins.ws.Server({ server: this.httpsServer });
|
||||||
wss.on('connection', function connection(ws) {
|
wss.on('connection', (ws: plugins.ws) => {
|
||||||
console.log('got connection for wsc');
|
console.log('got connection for wsc');
|
||||||
const wscConnected = plugins.smartpromise.defer();
|
const wscConnected = plugins.smartpromise.defer();
|
||||||
|
|
||||||
const wsc = new Websocket.default(`${ws.url}`);
|
const wsc = new plugins.ws(this.router.routeReq(ws), {
|
||||||
|
headers: {
|
||||||
|
Host: ws.url
|
||||||
|
}
|
||||||
|
});
|
||||||
wsc.on('open', () => {
|
wsc.on('open', () => {
|
||||||
wscConnected.resolve();
|
wscConnected.resolve();
|
||||||
});
|
});
|
||||||
|
@ -21,4 +21,12 @@ export class SmartproxyRouter {
|
|||||||
});
|
});
|
||||||
return correspodingReverseProxyConfig;
|
return correspodingReverseProxyConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public routeWs(ws: plugins.ws) {
|
||||||
|
const originalHost = plugins.url.parse(ws.url).host;
|
||||||
|
const correspodingReverseProxyConfig = this.reverseProxyConfigs.find(reverseConfig => {
|
||||||
|
return reverseConfig.hostName === originalHost;
|
||||||
|
});
|
||||||
|
return correspodingReverseProxyConfig.destinationIp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
// node native scope
|
// node native scope
|
||||||
import * as http from 'http';
|
import * as http from 'http';
|
||||||
import * as https from 'https';
|
import * as https from 'https';
|
||||||
|
import * as url from 'url';
|
||||||
|
|
||||||
export { http, https };
|
export { http, https, url };
|
||||||
|
|
||||||
// tsclass scope
|
// tsclass scope
|
||||||
import * as tsclass from '@tsclass/tsclass';
|
import * as tsclass from '@tsclass/tsclass';
|
||||||
|
Loading…
Reference in New Issue
Block a user