Compare commits

...

8 Commits

Author SHA1 Message Date
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
6 changed files with 47 additions and 1453 deletions

1441
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.6",
"version": "1.0.10",
"private": false,
"description": "a proxy for handling high workloads of proxying",
"main": "dist/index.js",
@ -17,14 +17,11 @@
"@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/smartrequest": "^1.1.20"
},
"files": [
"ts/*",

View File

@ -3,7 +3,7 @@ import * as smartproxy from '../ts/index';
tap.test('first test', async () => {
const testProxy = new smartproxy.SmartProxy();
await testProxy.start();
// await testProxy.start();
});
tap.start();

View File

@ -2,7 +2,7 @@ import * as plugins from './smartproxy.plugins';
export class SmartproxyRouter {
public routeReq(req: plugins.express.Request) {
return 'https://lossless.gmbh';
public routeReq(req: plugins.http.IncomingMessage) {
return 'lossless.gmbh';
}
}

View File

@ -4,7 +4,6 @@ import * as interfaces from './interfaces';
import { SmartproxyRouter } from './smartproxy.classes.router';
export class SmartProxy {
public expressInstance: plugins.express.Express;
public httpsServer: plugins.https.Server | plugins.http.Server;
public router = new SmartproxyRouter();
@ -19,26 +18,32 @@ export class SmartProxy {
* starts the proxyInstance
*/
public async start() {
this.expressInstance = plugins.express();
this.httpsServer = plugins.http.createServer(this.expressInstance);
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
}); */
}
// proxy middleware options
const proxyOptions: plugins.httpProxyMiddleware.Config = {
target: 'https://nullresolve.lossless.one',
changeOrigin: true, // needed for virtual hosted sites
ws: true, // proxy websockets
router: (req: plugins.express.Request) => {
return this.router.routeReq(req);
}
};
this.expressInstance.use(plugins.httpProxyMiddleware(proxyOptions));
this.httpsServer.on('upgrade', (req, socket) => {
})
this.httpsServer.listen(3000);

View File

@ -4,8 +4,9 @@ import * as https from 'https';
export { http, https };
// third party scope
import express from 'express';
import httpProxyMiddleware from 'http-proxy-middleware';
// pushrocks scope
import * as smartrequest from '@pushrocks/smartrequest';
export { express, httpProxyMiddleware };
export {
smartrequest
};