Compare commits

...

23 Commits

Author SHA1 Message Date
2b9b7cf691 1.0.15 2019-08-21 23:54:56 +02:00
0b7f5c4701 fix(core): update 2019-08-21 23:54:55 +02:00
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
ba55019846 1.0.4 2019-08-20 18:43:15 +02:00
6f967553d6 fix(core): update 2019-08-20 18:43:15 +02:00
10 changed files with 203 additions and 1456 deletions

View File

@ -14,4 +14,4 @@
"npmGlobalTools": [],
"npmAccessLevel": "public"
}
}
}

1460
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartproxy",
"version": "1.0.3",
"version": "1.0.15",
"private": false,
"description": "a proxy for handling high workloads of proxying",
"main": "dist/index.js",
@ -17,13 +17,25 @@
"@gitzone/tstest": "^1.0.15",
"@pushrocks/tapbundle": "^3.0.7",
"@types/node": "^12.7.2",
"tslint": "^5.11.0",
"tslint": "^5.19.0",
"tslint-config-prettier": "^1.15.0"
},
"dependencies": {
"@types/express": "^4.17.1",
"@types/http-proxy-middleware": "^0.19.3",
"express": "^4.17.1",
"http-proxy-middleware": "^0.19.1"
}
"@pushrocks/smartpromise": "^3.0.2",
"@pushrocks/smartrequest": "^1.1.20",
"@tsclass/tsclass": "^2.0.3",
"@types/ws": "^6.0.2",
"ws": "^7.1.2"
},
"files": [
"ts/*",
"ts_web/*",
"dist/*",
"dist_web/*",
"dist_ts_web/*",
"assets/*",
"cli.js",
"npmextra.json",
"readme.md"
]
}

26
readme.md Normal file
View File

@ -0,0 +1,26 @@
# @pushrocks/smartproxy
a proxy for handling high workloads of proxying
## Availabililty and Links
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartproxy)
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartproxy)
* [github.com (source mirror)](https://github.com/pushrocks/smartproxy)
* [docs (typedoc)](https://pushrocks.gitlab.io/smartproxy/)
## Status for master
[![build status](https://gitlab.com/pushrocks/smartproxy/badges/master/build.svg)](https://gitlab.com/pushrocks/smartproxy/commits/master)
[![coverage report](https://gitlab.com/pushrocks/smartproxy/badges/master/coverage.svg)](https://gitlab.com/pushrocks/smartproxy/commits/master)
[![npm downloads per month](https://img.shields.io/npm/dm/@pushrocks/smartproxy.svg)](https://www.npmjs.com/package/@pushrocks/smartproxy)
[![Known Vulnerabilities](https://snyk.io/test/npm/@pushrocks/smartproxy/badge.svg)](https://snyk.io/test/npm/@pushrocks/smartproxy)
[![TypeScript](https://img.shields.io/badge/TypeScript->=%203.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-prettier-ff69b4.svg)](https://prettier.io/)
## Usage
For further information read the linked docs at the top of this readme.
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)

View File

@ -1,8 +1,18 @@
import { expect, tap } from '@pushrocks/tapbundle';
import * as smartproxy from '../ts/index';
let testProxy: smartproxy.SmartProxy;
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();

View File

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

View File

@ -0,0 +1,80 @@
import * as plugins from './smartproxy.plugins';
import * as interfaces from './interfaces';
import { SmartproxyRouter } from './smartproxy.classes.router';
export class ProxyWorker {
public httpsServer: plugins.https.Server | plugins.http.Server;
public router = new SmartproxyRouter();
/**
* starts the proxyInstance
*/
public async start() {
this.httpsServer = plugins.http.createServer(async (req, res) => {
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() {
await this.start();
}
public async stop() {
const done = plugins.smartpromise.defer();
this.httpsServer.close(() => {
done.resolve();
});
}
}

View File

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

View File

@ -1,29 +1,22 @@
import * as plugins from './smartproxy.plugins';
import * as interfaces from './interfaces';
import { SmartproxyRouter } from './smartproxy.classes.router';
export class SmartProxy {
public expressInstance: plugins.express.Express;
public httpsServer: plugins.https.Server;
public router = new SmartproxyRouter();
public hostCandidates: interfaces.IHostConfig[] = [];
public addHostCandidate(hostCandidate: interfaces.IHostConfig) {
// TODO search for old hostCandidates with that target
this.hostCandidates.push(hostCandidate);
};
/**
* starts the proxyInstance
*/
public async start() {
this.expressInstance = plugins.express();
this.httpsServer = plugins.https.createServer(this.expressInstance);
}
public async update() {
await this.start();
async start () {
}
async stop () {
}
}

View File

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