fix(core): update

This commit is contained in:
Philipp Kunz 2019-08-20 22:26:44 +02:00
parent 1ccd53ce69
commit a5ecf0d9c1
4 changed files with 11 additions and 13 deletions

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

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

View File

@ -5,7 +5,7 @@ import { SmartproxyRouter } from './smartproxy.classes.router';
export class SmartProxy { export class SmartProxy {
public expressInstance: plugins.express.Express; public expressInstance: plugins.express.Express;
public httpsServer: plugins.https.Server; public httpsServer: plugins.https.Server | plugins.http.Server;
public router = new SmartproxyRouter(); public router = new SmartproxyRouter();
public hostCandidates: interfaces.IHostConfig[] = []; public hostCandidates: interfaces.IHostConfig[] = [];
@ -20,30 +20,26 @@ export class SmartProxy {
*/ */
public async start() { public async start() {
this.expressInstance = plugins.express(); this.expressInstance = plugins.express();
this.httpsServer = plugins.https.createServer(this.expressInstance); this.httpsServer = plugins.http.createServer(this.expressInstance);
for (const hostCandidate of this.hostCandidates) { for (const hostCandidate of this.hostCandidates) {
this.httpsServer.addContext(hostCandidate.hostName, { /* this.httpsServer.addContext(hostCandidate.hostName, {
cert: hostCandidate.publicKey, cert: hostCandidate.publicKey,
key: hostCandidate.privateKey key: hostCandidate.privateKey
}); }); */
} }
// proxy middleware options // proxy middleware options
const proxyOptions: plugins.httpProxyMiddleware.Config = { const proxyOptions: plugins.httpProxyMiddleware.Config = {
target: 'http://www.example.org', // target host target: 'https://nullresolve.lossless.one',
changeOrigin: true, // needed for virtual hosted sites changeOrigin: true, // needed for virtual hosted sites
ws: true, // proxy websockets ws: true, // proxy websockets
pathRewrite: {
'^/api/old-path': '/api/new-path', // rewrite path
'^/api/remove/path': '/path' // remove base path
},
router: (req: plugins.express.Request) => { router: (req: plugins.express.Request) => {
return this.router.routeReq(req); return this.router.routeReq(req);
} }
}; };
this.expressInstance.use(plugins.httpProxyMiddleware(proxyOptions)); this.expressInstance.use(plugins.httpProxyMiddleware(proxyOptions));
this.httpsServer.listen(3000);
} }

View File

@ -1,7 +1,8 @@
// 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 // third party scope
import express from 'express'; import express from 'express';