Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
akupiec
GitHub Repository: akupiec/mad-proxy
Path: blob/master/src/middlewares/reverseProxy.js
115 views
1
const config = require('../config/config');
2
const LOGGER = require('../config/logger');
3
const proxyServer = require('./utils/proxyServer');
4
5
module.exports = function (confProxy) {
6
return function reverseProxy(req, res) {
7
if(config.proxy.disabled) {
8
res.sendStatus(404);
9
return;
10
}
11
if(!req.mock.mockExists) {
12
LOGGER.debug(`Sending: ${req.method} ${req.url} ${req.mock.hash}`);
13
proxyServer.web(req, res, {target: confProxy.target}, function (e) {
14
LOGGER.fatal('Error occurred: Propably destination server is unavailable:\n', confProxy.target, req.originalUrl);
15
LOGGER.error(e);
16
});
17
}
18
};
19
};
20
21