Compare commits
38 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 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 | |||
| 1723275215 | |||
| 977d8b0310 | |||
| 5bb065f82b | |||
| 942b812f97 | |||
| 59a025b308 | |||
| 458e7d6b58 |
14983
package-lock.json
generated
14983
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
13
package.json
13
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartproxy",
|
"name": "@pushrocks/smartproxy",
|
||||||
"version": "3.0.35",
|
"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",
|
||||||
@@ -15,18 +15,19 @@
|
|||||||
"buildDocs": "tsdoc"
|
"buildDocs": "tsdoc"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.63",
|
"@gitzone/tsbuild": "^2.1.65",
|
||||||
"@gitzone/tstest": "^1.0.72",
|
"@gitzone/tsrun": "^1.2.39",
|
||||||
|
"@gitzone/tstest": "^1.0.73",
|
||||||
"@pushrocks/tapbundle": "^5.0.4",
|
"@pushrocks/tapbundle": "^5.0.4",
|
||||||
"@types/node": "^18.6.2"
|
"@types/node": "^18.7.8"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/lik": "^6.0.0",
|
"@pushrocks/lik": "^6.0.0",
|
||||||
"@pushrocks/smartdelay": "^2.0.13",
|
"@pushrocks/smartdelay": "^2.0.13",
|
||||||
"@pushrocks/smartpromise": "^3.1.7",
|
"@pushrocks/smartpromise": "^3.1.7",
|
||||||
"@pushrocks/smartrequest": "^2.0.6",
|
"@pushrocks/smartrequest": "^2.0.10",
|
||||||
"@pushrocks/smartstring": "^4.0.2",
|
"@pushrocks/smartstring": "^4.0.2",
|
||||||
"@tsclass/tsclass": "^4.0.17",
|
"@tsclass/tsclass": "^4.0.19",
|
||||||
"@types/ws": "^8.5.3",
|
"@types/ws": "^8.5.3",
|
||||||
"ws": "^8.8.1"
|
"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 = {
|
export const commitinfo = {
|
||||||
name: '@pushrocks/smartproxy',
|
name: '@pushrocks/smartproxy',
|
||||||
version: '3.0.35',
|
version: '3.0.54',
|
||||||
description: 'a proxy for handling high workloads of proxying'
|
description: 'a proxy for handling high workloads of proxying'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -186,7 +186,11 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
|
|||||||
destinationUrl,
|
destinationUrl,
|
||||||
{
|
{
|
||||||
method: originRequest.method,
|
method: originRequest.method,
|
||||||
headers: originRequest.headers,
|
headers: {
|
||||||
|
...originRequest.headers,
|
||||||
|
'X-Forwarded-Host': originRequest.headers.host,
|
||||||
|
'X-Forwarded-Proto': 'https'
|
||||||
|
},
|
||||||
keepAlive: true,
|
keepAlive: true,
|
||||||
},
|
},
|
||||||
true, // lets make this streaming
|
true, // lets make this streaming
|
||||||
@@ -241,47 +245,36 @@ 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) => {
|
wsServer.on('connection', async (wsIncoming: plugins.wsDefault, reqArg: plugins.http.IncomingMessage) => {
|
||||||
console.log('got connection for wsc');
|
console.log(`wss: got connection for wsc for https://${reqArg.headers.host}${reqArg.url}`);
|
||||||
let wscConnectedDeferred: plugins.smartpromise.Deferred<plugins.wsDefault>;
|
|
||||||
|
|
||||||
ws.on('message', async (message) => {
|
let wsOutgoing: plugins.wsDefault;
|
||||||
if (!wscConnectedDeferred) {
|
try {
|
||||||
wscConnectedDeferred = plugins.smartpromise.defer();
|
wsOutgoing = new plugins.wsDefault(`ws://${this.router.routeReq(reqArg).destinationIp}:${this.router.routeReq(reqArg).destinationPort}${reqArg.url}`);
|
||||||
const wsc = new plugins.wsDefault(this.router.routeWs(ws), {
|
} catch (err) {
|
||||||
headers: {
|
console.log(err);
|
||||||
Host: ws.url,
|
wsIncoming.terminate();
|
||||||
},
|
return;
|
||||||
});
|
}
|
||||||
|
|
||||||
wsc.on('open', () => {
|
wsIncoming.on("message", (message, isBinary) => {
|
||||||
wscConnectedDeferred.resolve(wsc);
|
console.log("client to upstream", message);
|
||||||
});
|
wsOutgoing.send(message, { binary: isBinary });
|
||||||
}
|
|
||||||
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();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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.keepAliveTimeout = 600 * 1000;
|
||||||
this.httpsServer.headersTimeout = 65000;
|
this.httpsServer.headersTimeout = 600 * 1000;
|
||||||
|
|
||||||
this.httpsServer.on('connection', (connection: plugins.net.Socket) => {
|
this.httpsServer.on('connection', (connection: plugins.net.Socket) => {
|
||||||
this.socketMap.add(connection);
|
this.socketMap.add(connection);
|
||||||
@@ -309,7 +302,7 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
|
|||||||
|
|
||||||
this.httpsServer.listen(this.options.port);
|
this.httpsServer.listen(this.options.port);
|
||||||
console.log(
|
console.log(
|
||||||
`ProxyWorker -> OK: now listening for new connections on port ${this.options.port}`
|
`NetworkProxy -> OK: now listening for new connections on port ${this.options.port}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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