mirror of
https://github.com/azaion/ui.git
synced 2026-04-22 11:56:34 +00:00
37 lines
1021 B
JavaScript
37 lines
1021 B
JavaScript
const { createProxyMiddleware } = require('http-proxy-middleware');
|
|
|
|
module.exports = function(app) {
|
|
// Get API base from environment variable or use default
|
|
const apiBase = process.env.REACT_APP_API_BASE || 'https://api.azaion.com';
|
|
|
|
console.log(`[proxy] /proxy -> ${apiBase}`);
|
|
|
|
// Proxy /proxy requests to the Azaion API
|
|
app.use(
|
|
'/proxy',
|
|
createProxyMiddleware({
|
|
target: apiBase,
|
|
changeOrigin: true,
|
|
pathRewrite: {
|
|
'^/proxy': '', // Remove /proxy prefix when forwarding
|
|
},
|
|
onProxyReq: (proxyReq) => {
|
|
// Ensure JSON content-type is kept if present
|
|
if (!proxyReq.getHeader('content-type')) {
|
|
proxyReq.setHeader('content-type', 'application/json');
|
|
}
|
|
},
|
|
logLevel: 'debug', // Enable logging for debugging
|
|
})
|
|
);
|
|
|
|
// Add server info endpoint so UI can auto-detect proxy status
|
|
app.get('/__server-info', (req, res) => {
|
|
res.json({
|
|
proxyEnabled: true,
|
|
apiBase: apiBase
|
|
});
|
|
});
|
|
};
|
|
|