fix(core): update
This commit is contained in:
parent
0e6c09aba5
commit
10cd3b3528
1427
package-lock.json
generated
1427
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -21,10 +21,7 @@
|
|||||||
"tslint-config-prettier": "^1.15.0"
|
"tslint-config-prettier": "^1.15.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/express": "^4.17.1",
|
"@pushrocks/smartrequest": "^1.1.19"
|
||||||
"@types/http-proxy-middleware": "^0.19.3",
|
|
||||||
"express": "^4.17.1",
|
|
||||||
"http-proxy-middleware": "^0.19.1"
|
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"ts/*",
|
"ts/*",
|
||||||
|
@ -3,7 +3,7 @@ import * as smartproxy from '../ts/index';
|
|||||||
|
|
||||||
tap.test('first test', async () => {
|
tap.test('first test', async () => {
|
||||||
const testProxy = new smartproxy.SmartProxy();
|
const testProxy = new smartproxy.SmartProxy();
|
||||||
// await testProxy.start();
|
await testProxy.start();
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
||||||
|
@ -2,7 +2,7 @@ import * as plugins from './smartproxy.plugins';
|
|||||||
|
|
||||||
export class SmartproxyRouter {
|
export class SmartproxyRouter {
|
||||||
|
|
||||||
public routeReq(req: plugins.express.Request) {
|
public routeReq(req: plugins.http.IncomingMessage) {
|
||||||
return 'https://lossless.gmbh';
|
return 'lossless.gmbh';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import * as interfaces from './interfaces';
|
|||||||
import { SmartproxyRouter } from './smartproxy.classes.router';
|
import { SmartproxyRouter } from './smartproxy.classes.router';
|
||||||
|
|
||||||
export class SmartProxy {
|
export class SmartProxy {
|
||||||
public expressInstance: plugins.express.Express;
|
|
||||||
public httpsServer: plugins.https.Server | plugins.http.Server;
|
public httpsServer: plugins.https.Server | plugins.http.Server;
|
||||||
public router = new SmartproxyRouter();
|
public router = new SmartproxyRouter();
|
||||||
|
|
||||||
@ -19,26 +18,32 @@ export class SmartProxy {
|
|||||||
* starts the proxyInstance
|
* starts the proxyInstance
|
||||||
*/
|
*/
|
||||||
public async start() {
|
public async start() {
|
||||||
this.expressInstance = plugins.express();
|
this.httpsServer = plugins.http.createServer(async (req, res) => {
|
||||||
this.httpsServer = plugins.http.createServer(this.expressInstance);
|
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) {
|
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
|
||||||
}); */
|
}); */
|
||||||
}
|
}
|
||||||
|
this.httpsServer.on('upgrade', (req, socket) => {
|
||||||
// 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.listen(3000);
|
this.httpsServer.listen(3000);
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,8 +4,9 @@ import * as https from 'https';
|
|||||||
|
|
||||||
export { http, https };
|
export { http, https };
|
||||||
|
|
||||||
// third party scope
|
// pushrocks scope
|
||||||
import express from 'express';
|
import * as smartrequest from '@pushrocks/smartrequest';
|
||||||
import httpProxyMiddleware from 'http-proxy-middleware';
|
|
||||||
|
|
||||||
export { express, httpProxyMiddleware };
|
export {
|
||||||
|
smartrequest
|
||||||
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user