Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
1ccd53ce69 | |||
1264542410 |
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@pushrocks/smartproxy",
|
||||
"version": "1.0.4",
|
||||
"version": "1.0.5",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@pushrocks/smartproxy",
|
||||
"version": "1.0.4",
|
||||
"version": "1.0.5",
|
||||
"private": false,
|
||||
"description": "a proxy for handling high workloads of proxying",
|
||||
"main": "dist/index.js",
|
||||
|
@ -1,6 +1,6 @@
|
||||
export interface IHostConfig {
|
||||
hostName: string;
|
||||
destination: string;
|
||||
destinationIp: string;
|
||||
destinationPort: number;
|
||||
privateKey: string;
|
||||
publicKey: string;
|
||||
|
@ -1,3 +1,8 @@
|
||||
import * as plugins from './smartproxy.plugins';
|
||||
|
||||
export class SmartproxyRouter {}
|
||||
export class SmartproxyRouter {
|
||||
|
||||
public routeReq(req: plugins.express.Request) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,31 @@ export class SmartProxy {
|
||||
public async start() {
|
||||
this.expressInstance = plugins.express();
|
||||
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() {
|
||||
|
@ -5,6 +5,6 @@ export { https };
|
||||
|
||||
// third party scope
|
||||
import express from 'express';
|
||||
import * as httpProxyMiddleware from 'http-proxy-middleware';
|
||||
import httpProxyMiddleware from 'http-proxy-middleware';
|
||||
|
||||
export { express, httpProxyMiddleware };
|
||||
|
Reference in New Issue
Block a user