Compare commits

...

10 Commits

Author SHA1 Message Date
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
7 changed files with 58 additions and 1436 deletions

1429
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.9",
"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",
@ -21,10 +21,7 @@
"tslint-config-prettier": "^1.15.0" "tslint-config-prettier": "^1.15.0"
}, },
"dependencies": { "dependencies": {
"@types/express": "^4.17.1", "@pushrocks/smartrequest": "^1.1.19"
"@types/http-proxy-middleware": "^0.19.3",
"express": "^4.17.1",
"http-proxy-middleware": "^0.19.1"
}, },
"files": [ "files": [
"ts/*", "ts/*",

View File

@ -2,7 +2,8 @@ import { expect, tap } from '@pushrocks/tapbundle';
import * as smartproxy from '../ts/index'; import * as smartproxy from '../ts/index';
tap.test('first test', async () => { tap.test('first test', async () => {
console.log(smartproxy); const testProxy = new smartproxy.SmartProxy();
// await testProxy.start();
}); });
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

@ -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

@ -4,8 +4,7 @@ import * as interfaces from './interfaces';
import { SmartproxyRouter } from './smartproxy.classes.router'; import { SmartproxyRouter } from './smartproxy.classes.router';
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,8 +18,35 @@ 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
}); */
}
this.httpsServer.on('upgrade', (req, socket) => {
})
this.httpsServer.listen(3000);
} }
public async update() { public async update() {

View File

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