Compare commits

...

19 Commits

Author SHA1 Message Date
23fa6a6511 1.0.14 2019-08-21 23:41:06 +02:00
ff8e185ec3 fix(core): update 2019-08-21 23:41:06 +02:00
c32a56d921 1.0.13 2019-08-21 15:09:33 +02:00
69233e8a3b fix(core): update 2019-08-21 15:09:32 +02:00
23e6977d81 1.0.12 2019-08-21 15:07:47 +02:00
9f57b3b638 1.0.11 2019-08-21 13:06:14 +02:00
5df0a53efe fix(core): update 2019-08-21 13:06:13 +02:00
6d1a781b9a 1.0.10 2019-08-21 13:04:00 +02:00
81c9f3b72e fix(core): update 2019-08-21 13:04:00 +02:00
c8ac0498c8 1.0.9 2019-08-21 03:20:41 +02:00
ee0900f3c0 fix(core): update 2019-08-21 03:20:40 +02:00
7c46d16686 1.0.8 2019-08-21 03:14:42 +02:00
10cd3b3528 fix(core): update 2019-08-21 03:14:42 +02:00
0e6c09aba5 1.0.7 2019-08-20 23:21:12 +02:00
2f4916f552 fix(core): update 2019-08-20 23:21:12 +02:00
29bddf198f 1.0.6 2019-08-20 22:26:44 +02:00
a5ecf0d9c1 fix(core): update 2019-08-20 22:26:44 +02:00
1ccd53ce69 1.0.5 2019-08-20 19:02:13 +02:00
1264542410 fix(core): update 2019-08-20 19:02:13 +02:00
8 changed files with 149 additions and 1440 deletions

1460
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/smartproxy", "name": "@pushrocks/smartproxy",
"version": "1.0.4", "version": "1.0.14",
"private": false, "private": false,
"description": "a proxy for handling high workloads of proxying", "description": "a proxy for handling high workloads of proxying",
"main": "dist/index.js", "main": "dist/index.js",
@ -17,14 +17,15 @@
"@gitzone/tstest": "^1.0.15", "@gitzone/tstest": "^1.0.15",
"@pushrocks/tapbundle": "^3.0.7", "@pushrocks/tapbundle": "^3.0.7",
"@types/node": "^12.7.2", "@types/node": "^12.7.2",
"tslint": "^5.11.0", "tslint": "^5.19.0",
"tslint-config-prettier": "^1.15.0" "tslint-config-prettier": "^1.15.0"
}, },
"dependencies": { "dependencies": {
"@types/express": "^4.17.1", "@pushrocks/smartpromise": "^3.0.2",
"@types/http-proxy-middleware": "^0.19.3", "@pushrocks/smartrequest": "^1.1.20",
"express": "^4.17.1", "@tsclass/tsclass": "^2.0.3",
"http-proxy-middleware": "^0.19.1" "@types/ws": "^6.0.2",
"ws": "^7.1.2"
}, },
"files": [ "files": [
"ts/*", "ts/*",

View File

@ -1,8 +1,18 @@
import { expect, tap } from '@pushrocks/tapbundle'; import { expect, tap } from '@pushrocks/tapbundle';
import * as smartproxy from '../ts/index'; import * as smartproxy from '../ts/index';
let testProxy: smartproxy.SmartProxy;
tap.test('first test', async () => { tap.test('first test', async () => {
console.log(smartproxy); testProxy = new smartproxy.SmartProxy();
});
tap.test('should start the testproxy', async () => {
await testProxy.start();
});
tap.test('should close the testproxy', async () => {
await testProxy.stop();
}); });
tap.start(); tap.start();

View File

@ -1,6 +1,6 @@
export interface IHostConfig { export interface IHostConfig {
hostName: string; hostName: string;
destination: string; destinationIp: string;
destinationPort: number; destinationPort: number;
privateKey: string; privateKey: string;
publicKey: string; publicKey: string;

View File

@ -0,0 +1,5 @@
import * as plugins from './smartproxy.plugins';
export class ProxyWorker {
}

View File

@ -1,3 +1,8 @@
import * as plugins from './smartproxy.plugins'; import * as plugins from './smartproxy.plugins';
export class SmartproxyRouter {} export class SmartproxyRouter {
public routeReq(req: plugins.http.IncomingMessage) {
return 'lossless.gmbh';
}
}

View File

@ -2,10 +2,10 @@ import * as plugins from './smartproxy.plugins';
import * as interfaces from './interfaces'; import * as interfaces from './interfaces';
import { SmartproxyRouter } from './smartproxy.classes.router'; import { SmartproxyRouter } from './smartproxy.classes.router';
import { Socket } from 'net';
export class SmartProxy { export class SmartProxy {
public expressInstance: plugins.express.Express; public httpsServer: plugins.https.Server | plugins.http.Server;
public httpsServer: plugins.https.Server;
public router = new SmartproxyRouter(); public router = new SmartproxyRouter();
public hostCandidates: interfaces.IHostConfig[] = []; public hostCandidates: interfaces.IHostConfig[] = [];
@ -19,11 +19,71 @@ export class SmartProxy {
* starts the proxyInstance * starts the proxyInstance
*/ */
public async start() { public async start() {
this.expressInstance = plugins.express(); this.httpsServer = plugins.http.createServer(async (req, res) => {
this.httpsServer = plugins.https.createServer(this.expressInstance); req.headers.host = this.router.routeReq(req);
const response = await plugins.smartrequest.request(
`https://${req.headers.host}${req.url}`,
{
method: req.method,
headers: req.headers
},
true
);
res.statusCode = response.statusCode;
for (const header of Object.keys(response.headers)) {
res.setHeader(header, response.headers[header]);
}
response.on('data', data => {
res.write(data);
});
response.on('end', () => {
res.end();
});
});
for (const hostCandidate of this.hostCandidates) {
/* this.httpsServer.addContext(hostCandidate.hostName, {
cert: hostCandidate.publicKey,
key: hostCandidate.privateKey
}); */
}
// Enable websockets
const wss = new plugins.ws.Server({ server: this.httpsServer });
wss.on('connection', function connection(ws) {
const wscConnected = plugins.smartpromise.defer();
const wsc = new plugins.ws(`${ws.url}`);
wsc.on('open', () => {
wscConnected.resolve();
});
ws.on('message', async (message) => {
await wscConnected.promise;
wsc.emit('message', message);
});
wsc.on('message', (message) => {
ws.emit('message', message);
});
// handle closing
ws.on('close', (message) => {
wsc.close();
});
wsc.on('close', (message) => {
ws.close();
});
});
this.httpsServer.listen(3000);
} }
public async update() { public async update() {
await this.start(); await this.start();
} }
public async stop() {
const done = plugins.smartpromise.defer();
this.httpsServer.close(() => {
done.resolve();
});
}
} }

View File

@ -1,10 +1,22 @@
// node native scope // node native scope
import * as https from 'https'; import crypto from 'crypto';
import http from 'http';
import https from 'https';
export { https }; export { crypto, http, https };
// pushrocks scope
import * as smartpromise from '@pushrocks/smartpromise';
import * as smartrequest from '@pushrocks/smartrequest';
export {
smartrequest,
smartpromise
};
// third party scope // third party scope
import express from 'express'; import ws from 'ws';
import * as httpProxyMiddleware from 'http-proxy-middleware';
export { express, httpProxyMiddleware }; export {
ws
};