Compare commits

...

4 Commits

Author SHA1 Message Date
0e6c09aba5 1.0.7 2019-08-20 23:21:12 +02:00
2f4916f552 fix(core): update 2019-08-20 23:21:12 +02:00
29bddf198f 1.0.6 2019-08-20 22:26:44 +02:00
a5ecf0d9c1 fix(core): update 2019-08-20 22:26:44 +02:00
6 changed files with 13 additions and 15 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/smartproxy", "name": "@pushrocks/smartproxy",
"version": "1.0.5", "version": "1.0.7",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/smartproxy", "name": "@pushrocks/smartproxy",
"version": "1.0.5", "version": "1.0.7",
"private": false, "private": false,
"description": "a proxy for handling high workloads of proxying", "description": "a proxy for handling high workloads of proxying",
"main": "dist/index.js", "main": "dist/index.js",

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';