fix(core): update

This commit is contained in:
Philipp Kunz 2019-08-21 03:14:42 +02:00
parent 0e6c09aba5
commit 10cd3b3528
6 changed files with 38 additions and 1444 deletions

1427
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -21,10 +21,7 @@
"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.19"
},
"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
};