-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
34 lines (26 loc) · 1010 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const http = require('http');
const https = require('https');
const httpProxy = require('http-proxy');
const RuntimeValidator = require('./services/RuntimeValidator');
const Logger = require('./services/reportConsole');
global._ = require('lodash');
global.ERROR = require('./services/errorCodes');
global.$ = new Logger();
if (process.env.NODE_ENV !== 'production') {
require('dotenv').config();
}
const runtimeValidator = new RuntimeValidator();
const agent = new http.Agent({ path: process.env.TARGET, rejectUnauthorized: false });
const proxyServer = httpProxy.createProxyServer({
target: process.env.TARGET,
selfHandleResponse: true,
changeOrigin: true,
agent
});
proxyServer.on('proxyRes',(proxyRes, req, res) => {
runtimeValidator.validate(proxyRes, req, res);
});
const httpServer = http.createServer((req, res)=>proxyServer.web(req, res));
httpServer.listen(process.env.PORT || 5050,()=>{
console.log('SERVER', `listining on port ${process.env.PORT || 5050}`);
});