Skip to content

Commit 9753bd2

Browse files
committed
WEB-547 feat(proxy): forward fineract provider requests to sandbox for local dev
1 parent 53a238a commit 9753bd2

File tree

5 files changed

+240
-147
lines changed

5 files changed

+240
-147
lines changed

README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,52 @@ When using the development server with basic authentication:
132132
- **Build for production:** `ng build --configuration production` or `npm run build:prod`
133133
- **Get Angular CLI help:** `ng help`
134134

135+
## Proxy Configuration
136+
137+
The web app includes a proxy configuration (`proxy.conf.js`) that allows you to forward API requests to a remote Fineract backend during local development. This helps avoid CORS issues and enables you to work against production-like environments.
138+
139+
### Using the Sandbox Proxy (Default)
140+
141+
By default, the proxy forwards `/fineract-provider` requests to the Mifos sandbox environment:
142+
143+
- **Target:** `https://sandbox.mifos.community`
144+
- **API Endpoint:** `https://apis.mifos.community` (exposed in the sandbox)
145+
- **System Reset:** Every 6 hours
146+
147+
**Sandbox Environment Variables:**
148+
149+
```bash
150+
FINERACT_API_URLS=https://apis.mifos.community
151+
FINERACT_API_URL=https://apis.mifos.community
152+
FINERACT_API_PROVIDER=/1.0/core/api
153+
FINERACT_API_ACTUATOR=/1.0/core
154+
FINERACT_API_VERSION=/v1
155+
FINERACT_PLATFORM_TENANT_IDENTIFIER=default
156+
MIFOS_DEFAULT_LANGUAGE=en-US
157+
MIFOS_SUPPORTED_LANGUAGES=cs-CS,de-DE,en-US,es-MX,fr-FR,it-IT,ko-KO,li-LI,lv-LV,ne-NE,pt-PT,sw-SW
158+
MIFOS_PRELOAD_CLIENTS=true
159+
MIFOS_DEFAULT_CHAR_DELIMITER=,
160+
```
161+
162+
### Using a Local Fineract Instance
163+
164+
To proxy to a local Fineract server instead:
165+
166+
1. Open `proxy.conf.js`
167+
2. Comment out the sandbox proxy configuration
168+
3. Uncomment the localhost proxy configuration (lines marked with `// Uncomment this configuration...`)
169+
4. Ensure your local Fineract instance is running on `http://localhost:8443`
170+
5. Restart the development server
171+
172+
### Proxy Features
173+
174+
- **CORS Avoidance:** Eliminates cross-origin issues during local development
175+
- **Error Handling:** Gracefully handles proxy failures with detailed logging
176+
- **Corporate Proxy Support:** Maintains support for corporate proxy agents via `HTTP_PROXY` environment variable
177+
- **Debug Logging:** All proxy requests are logged for troubleshooting
178+
179+
For more details on proxy configuration, see the [backend proxy documentation](./docs/backend-proxy.md).
180+
135181
## Configuration Options
136182

137183
### Environment Variables for Docker

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)