fix(core): update
This commit is contained in:
		
							
								
								
									
										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" | ||||
|   }, | ||||
|   "dependencies": { | ||||
|     "@types/express": "^4.17.1", | ||||
|     "@types/http-proxy-middleware": "^0.19.3", | ||||
|     "express": "^4.17.1", | ||||
|     "http-proxy-middleware": "^0.19.1" | ||||
|     "@pushrocks/smartrequest": "^1.1.19" | ||||
|   }, | ||||
|   "files": [ | ||||
|     "ts/*", | ||||
|   | ||||
| @@ -3,7 +3,7 @@ import * as smartproxy from '../ts/index'; | ||||
|  | ||||
| tap.test('first test', async () => { | ||||
|   const testProxy = new smartproxy.SmartProxy(); | ||||
|   // await testProxy.start(); | ||||
|   await testProxy.start(); | ||||
| }); | ||||
|  | ||||
| tap.start(); | ||||
|   | ||||
| @@ -2,7 +2,7 @@ import * as plugins from './smartproxy.plugins'; | ||||
|  | ||||
| export class SmartproxyRouter { | ||||
|  | ||||
|   public routeReq(req: plugins.express.Request) { | ||||
|     return 'https://lossless.gmbh'; | ||||
|   public routeReq(req: plugins.http.IncomingMessage) { | ||||
|     return 'lossless.gmbh'; | ||||
|   } | ||||
| } | ||||
|   | ||||
| @@ -4,7 +4,6 @@ import * as interfaces from './interfaces'; | ||||
| import { SmartproxyRouter } from './smartproxy.classes.router'; | ||||
|  | ||||
| export class SmartProxy { | ||||
|   public expressInstance: plugins.express.Express; | ||||
|   public httpsServer: plugins.https.Server | plugins.http.Server; | ||||
|   public router = new SmartproxyRouter(); | ||||
|  | ||||
| @@ -19,26 +18,32 @@ export class SmartProxy { | ||||
|    * starts the proxyInstance | ||||
|    */ | ||||
|   public async start() { | ||||
|     this.expressInstance = plugins.express(); | ||||
|     this.httpsServer = plugins.http.createServer(this.expressInstance); | ||||
|     this.httpsServer = plugins.http.createServer(async (req, res) => { | ||||
|       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) { | ||||
|       /* this.httpsServer.addContext(hostCandidate.hostName, { | ||||
|         cert: hostCandidate.publicKey, | ||||
|         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); | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -4,8 +4,9 @@ import * as https from 'https'; | ||||
|  | ||||
| export { http, https }; | ||||
|  | ||||
| // third party scope | ||||
| import express from 'express'; | ||||
| import httpProxyMiddleware from 'http-proxy-middleware'; | ||||
| // pushrocks scope | ||||
| import * as smartrequest from '@pushrocks/smartrequest'; | ||||
|  | ||||
| export { express, httpProxyMiddleware }; | ||||
| export { | ||||
|   smartrequest | ||||
| }; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user