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 }); }); };