fix(core): update

This commit is contained in:
Philipp Kunz 2019-08-20 19:02:13 +02:00
parent ba55019846
commit 1264542410
4 changed files with 33 additions and 3 deletions

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.express.Request) {
return '';
}
}

View File

@ -21,6 +21,31 @@ 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.https.createServer(this.expressInstance);
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: 'http://www.example.org', // target host
changeOrigin: true, // needed for virtual hosted sites
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) => {
return this.router.routeReq(req);
}
};
this.expressInstance.use(plugins.httpProxyMiddleware(proxyOptions));
} }
public async update() { public async update() {

View File

@ -5,6 +5,6 @@ export { https };
// third party scope // third party scope
import express from 'express'; import express from 'express';
import * as httpProxyMiddleware from 'http-proxy-middleware'; import httpProxyMiddleware from 'http-proxy-middleware';
export { express, httpProxyMiddleware }; export { express, httpProxyMiddleware };