Skip to content

Commit 449f1a0

Browse files
committed
WEB-547 feat(proxy): forward fineract provider requests to sandbox for local dev
1 parent e52691b commit 449f1a0

File tree

1 file changed

+43
-4
lines changed

1 file changed

+43
-4
lines changed

proxy.conf.js

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,51 @@ const { HttpsProxyAgent } = require('https-proxy-agent');
1010
*/
1111
const proxyConfig = [
1212
{
13-
context: '/api',
14-
pathRewrite: { '^/api': '' },
15-
target: 'https://api.chucknorris.io',
13+
context: ['/fineract-provider'],
14+
target: 'https://sandbox.mifos.community',
15+
pathRewrite: { '^/fineract-provider': '' },
1616
changeOrigin: true,
17-
secure: false
17+
secure: true,
18+
logLevel: 'debug',
19+
onProxyReq: function (proxyReq, req, res) {
20+
const rewrittenPath = (req.url || '').replace(/^\/fineract-provider/, '');
21+
console.log('[Proxy] Proxying:', req.method, req.url, '->', this.target + rewrittenPath);
22+
},
23+
onError: function (err, req, res) {
24+
console.error(
25+
'[Proxy] Error while proxying request:',
26+
req && req.method,
27+
req && req.url,
28+
'->',
29+
this.target,
30+
'-',
31+
err && err.message
32+
);
33+
if (res && !res.headersSent) {
34+
res.writeHead(502, { 'Content-Type': 'text/plain' });
35+
res.end('Proxy error: ' + (err && err.message ? err.message : 'Unknown error'));
36+
}
37+
}
1838
}
39+
// Uncomment this configuration to proxy to a local Fineract instance instead
40+
// {
41+
// context: ['/fineract-provider'],
42+
// target: 'http://localhost:8443',
43+
// pathRewrite: { '^/fineract-provider': '' },
44+
// changeOrigin: true,
45+
// secure: false,
46+
// logLevel: 'debug',
47+
// onProxyReq: function(proxyReq, req, res) {
48+
// console.log('[Proxy] Proxying:', req.method, req.url, '->', this.target + req.url);
49+
// },
50+
// onError: function(err, req, res) {
51+
// console.error('[Proxy] Error while proxying request:', req && req.method, req && req.url, '->', this.target, '-', err && err.message);
52+
// if (res && !res.headersSent) {
53+
// res.writeHead(502, { 'Content-Type': 'text/plain' });
54+
// res.end('Proxy error: ' + (err && err.message ? err.message : 'Unknown error'));
55+
// }
56+
// }
57+
// }
1958
];
2059

2160
/*

0 commit comments

Comments
 (0)