Compare commits

...

10 Commits

Author SHA1 Message Date
6dd3e473c6 1.0.31 2019-09-29 01:06:07 +02:00
3856a1d7fb fix(core): update 2019-09-29 01:06:07 +02:00
fb76ecfd8a 1.0.30 2019-09-24 16:27:34 +02:00
6c84406574 fix(core): update 2019-09-24 16:27:34 +02:00
945065279f 1.0.29 2019-09-24 16:21:58 +02:00
07a8d9bec6 fix(websockets): now proxying websockets as well 2019-09-24 16:21:57 +02:00
2c55a6b819 1.0.28 2019-09-23 19:20:54 +02:00
8f4421fbc3 fix(core): update 2019-09-23 19:20:53 +02:00
5eebc434bb 1.0.27 2019-09-20 19:19:33 +02:00
ed03c3ec4b fix(core): update 2019-09-20 19:19:33 +02:00
6 changed files with 107 additions and 33 deletions

59
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartproxy",
"version": "1.0.26",
"version": "1.0.31",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@ -259,13 +259,14 @@
"integrity": "sha512-9kHBWyDFjQ6cV1rseOfge02EH6huh/mrtqxlFoJoxnMaGWf5F8H3UEsskBBUGI6QKE1Bl8evr74AIKWwJ0r/bA=="
},
"@pushrocks/smartrequest": {
"version": "1.1.27",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartrequest/-/smartrequest-1.1.27.tgz",
"integrity": "sha512-GJO6duKBro2oILtXduVQwxA50AzjHZbKP0P32OoiM+B1ftoQFf4D8zSs/SCljNKXUqS8SZ9IMQVlKLfRC4nu+A==",
"version": "1.1.35",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartrequest/-/smartrequest-1.1.35.tgz",
"integrity": "sha512-1DOnt0628rkxDnX0zIoPHFxBwvjp6iIYkyaZshzFeACARmc+1yRYKiEu5pDahwhWhrCkK7xaAL+iLqnxxp+tWg==",
"requires": {
"@pushrocks/smartpromise": "^3.0.2",
"@types/form-data": "^2.2.1",
"form-data": "^2.3.3"
"@pushrocks/smartpromise": "^3.0.5",
"@types/form-data": "^2.5.0",
"agentkeepalive": "^4.0.2",
"form-data": "^2.5.1"
}
},
"@pushrocks/smartrx": {
@ -453,9 +454,9 @@
"integrity": "sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA=="
},
"@types/node": {
"version": "12.7.5",
"resolved": "https://verdaccio.lossless.one/@types%2fnode/-/node-12.7.5.tgz",
"integrity": "sha512-9fq4jZVhPNW8r+UYKnxF1e2HkDWOWKM5bC2/7c9wPV835I0aOrVbS/Hw/pWPk2uKrNXQqg9Z959Kz+IYDd5p3w=="
"version": "12.7.8",
"resolved": "https://verdaccio.lossless.one/@types%2fnode/-/node-12.7.8.tgz",
"integrity": "sha512-FMdVn84tJJdV+xe+53sYiZS4R5yn1mAIxfj+DVoNiQjTYz1+OYmjwEZr1ev9nU0axXwda0QDbYl06QHanRVH3A=="
},
"@types/portscanner": {
"version": "2.1.0",
@ -504,6 +505,31 @@
"es6-promisify": "^5.0.0"
}
},
"agentkeepalive": {
"version": "4.0.2",
"resolved": "https://verdaccio.lossless.one/agentkeepalive/-/agentkeepalive-4.0.2.tgz",
"integrity": "sha512-A5gSniD4xMCYtSD4ilUHpQRB9ZbNjtIPittKUv7bA0j0UCwbT3EJBUYLKPJ/dtmaXRYWI2mG4/O90xbi7oahNw==",
"requires": {
"debug": "^4.1.0",
"depd": "^1.1.2",
"humanize-ms": "^1.2.1"
},
"dependencies": {
"debug": {
"version": "4.1.1",
"resolved": "https://verdaccio.lossless.one/debug/-/debug-4.1.1.tgz",
"integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==",
"requires": {
"ms": "^2.1.1"
}
},
"ms": {
"version": "2.1.2",
"resolved": "https://verdaccio.lossless.one/ms/-/ms-2.1.2.tgz",
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
}
}
},
"ansi-256-colors": {
"version": "1.1.0",
"resolved": "https://verdaccio.lossless.one/ansi-256-colors/-/ansi-256-colors-1.1.0.tgz",
@ -887,6 +913,11 @@
"resolved": "https://verdaccio.lossless.one/delayed-stream/-/delayed-stream-1.0.0.tgz",
"integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk="
},
"depd": {
"version": "1.1.2",
"resolved": "https://verdaccio.lossless.one/depd/-/depd-1.1.2.tgz",
"integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak="
},
"diff": {
"version": "4.0.1",
"resolved": "https://verdaccio.lossless.one/diff/-/diff-4.0.1.tgz",
@ -1138,6 +1169,14 @@
"debug": "^3.1.0"
}
},
"humanize-ms": {
"version": "1.2.1",
"resolved": "https://verdaccio.lossless.one/humanize-ms/-/humanize-ms-1.2.1.tgz",
"integrity": "sha1-xG4xWaKT9riW2ikxbYtv6Lt5u+0=",
"requires": {
"ms": "^2.0.0"
}
},
"inflight": {
"version": "1.0.6",
"resolved": "https://verdaccio.lossless.one/inflight/-/inflight-1.0.6.tgz",

View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartproxy",
"version": "1.0.26",
"version": "1.0.31",
"private": false,
"description": "a proxy for handling high workloads of proxying",
"main": "dist/index.js",
@ -16,14 +16,14 @@
"@gitzone/tsbuild": "^2.1.17",
"@gitzone/tstest": "^1.0.15",
"@pushrocks/tapbundle": "^3.0.13",
"@types/node": "^12.7.5",
"@types/node": "^12.7.8",
"tslint": "^5.20.0",
"tslint-config-prettier": "^1.15.0"
},
"dependencies": {
"@pushrocks/smartnetwork": "^1.1.14",
"@pushrocks/smartpromise": "^3.0.5",
"@pushrocks/smartrequest": "^1.1.27",
"@pushrocks/smartrequest": "^1.1.35",
"@pushrocks/smartspawn": "^2.0.9",
"@pushrocks/smartsystem": "^2.0.9",
"@tsclass/tsclass": "^2.0.6",

View File

@ -14,7 +14,7 @@ tap.test('should start the testproxy', async () => {
tap.test('should supply reverse proxy config', async () => {
testProxy.updateReversConfigs([{
destinationIp: 'localhost',
destinationPort: '8080',
destinationPort: '3000',
hostName: 'central.eu',
privateKey: `-----BEGIN PRIVATE KEY-----
MIIJRQIBADANBgkqhkiG9w0BAQEFAASCCS8wggkrAgEAAoICAQDi2F/0kQr96mhe

View File

@ -3,7 +3,7 @@ import * as plugins from './smartproxy.plugins';
import { SmartproxyRouter } from './smartproxy.classes.router';
export class ProxyWorker {
public hostCandidates: plugins.tsclass.network.IReverseProxyConfig[] = [];
public proxyConfigs: plugins.tsclass.network.IReverseProxyConfig[] = [];
public httpsServer: plugins.https.Server; // | plugins.http.Server;
public port = 8001;
public router = new SmartproxyRouter();
@ -97,15 +97,33 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
}, async (req, res) => {
console.log('got request');
const destinationConfig = this.router.routeReq(req);
let destinationUrl: string;
if (destinationConfig) {
destinationUrl = `http://${destinationConfig.destinationIp}:${destinationConfig.destinationPort}${req.url}`;
} else {
res.writeHead(404);
res.end('This route is not available on this server\n');
return;
}
console.log(destinationUrl);
const response = await plugins.smartrequest.request(
`http://${destinationConfig.destinationIp}:${destinationConfig.destinationPort}${req.url}`,
destinationUrl,
{
method: req.method,
headers: req.headers
},
true // lets make this streaming
true, // lets make this streaming
(request) => {
req.on('data', data => {
request.write(data);
});
req.on('end', data => {
request.end();
});
}
);
res.statusCode = response.statusCode;
console.log(response.statusCode);
for (const header of Object.keys(response.headers)) {
res.setHeader(header, response.headers[header]);
}
@ -117,15 +135,17 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
});
});
const Websocket = await import('ws');
// Enable websockets
const wss = new plugins.ws.Server({ server: this.httpsServer });
wss.on('connection', function connection(ws) {
wss.on('connection', (ws: plugins.wsDefault) => {
console.log('got connection for wsc');
const wscConnected = plugins.smartpromise.defer();
const wsc = new Websocket.default(`${ws.url}`);
const wsc = new plugins.wsDefault(this.router.routeWs(ws), {
headers: {
Host: ws.url
}
});
wsc.on('open', () => {
wscConnected.resolve();
});
@ -146,15 +166,16 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
ws.close();
});
});
this.httpsServer.keepAliveTimeout = 61000;
this.httpsServer.headersTimeout = 65000;
this.httpsServer.listen(this.port);
console.log(`OK: now listening for new connections on port ${this.port}`);
}
public async updateCandidates(arrayOfReverseCandidates: plugins.tsclass.IReverseProxyConfig[]) {
this.hostCandidates = arrayOfReverseCandidates;
this.router.setNewCandidates(arrayOfReverseCandidates);
for (const hostCandidate of this.hostCandidates) {
public async updateProxyConfigs(proxyConfigsArg: plugins.tsclass.IReverseProxyConfig[]) {
this.proxyConfigs = proxyConfigsArg;
this.router.setNewProxyConfigs(proxyConfigsArg);
for (const hostCandidate of this.proxyConfigs) {
// console.log(hostCandidate);
this.httpsServer.addContext(hostCandidate.hostName, {
cert: hostCandidate.publicKey,
@ -185,7 +206,7 @@ const proxyWorkerCalls = {
await proxyWorkerInstance.start();
},
updateReverseConfigs: async (configArray: plugins.tsclass.network.IReverseProxyConfig[]) => {
await proxyWorkerInstance.updateCandidates(configArray);
await proxyWorkerInstance.updateProxyConfigs(configArray);
}
};

View File

@ -1,20 +1,32 @@
import * as plugins from './smartproxy.plugins';
export class SmartproxyRouter {
public reverseCandidates: plugins.tsclass.network.IReverseProxyConfig[] = [];
public reverseProxyConfigs: plugins.tsclass.network.IReverseProxyConfig[] = [];
/**
* sets a new set of reverse configs to be routed to
* @param reverseCandidatesArg
*/
public setNewCandidates(reverseCandidatesArg: plugins.tsclass.network.IReverseProxyConfig[]) {
this.reverseCandidates = reverseCandidatesArg;
public setNewProxyConfigs(reverseCandidatesArg: plugins.tsclass.network.IReverseProxyConfig[]) {
this.reverseProxyConfigs = reverseCandidatesArg;
}
/**
* routes a request
*/
public routeReq(req: plugins.http.IncomingMessage): plugins.tsclass.network.IReverseProxyConfig {
const originalHost = req.headers.host;
const correspodingReverseProxyConfig = this.reverseCandidates.find(reverseConfig => {
const correspodingReverseProxyConfig = this.reverseProxyConfigs.find(reverseConfig => {
return reverseConfig.hostName === originalHost;
});
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;
}
}

View File

@ -1,8 +1,9 @@
// node native scope
import * as http from 'http';
import * as https from 'https';
import * as url from 'url';
export { http, https };
export { http, https, url };
// tsclass scope
import * as tsclass from '@tsclass/tsclass';
@ -19,5 +20,6 @@ export { smartrequest, smartpromise, smartspawn, smartsystem };
// third party scope
import * as ws from 'ws';
import wsDefault from 'ws';
export { ws };
export { wsDefault, ws };