fix(bff): agregar endpoint /settings/demo-mode y proxy /api/v1 en Express Node.js y Flask API

This commit is contained in:
2026-09-23 16:42:11 -03:00
parent dd4a4c042a
commit 6907134c5e
6 changed files with 173 additions and 7 deletions
+25
View File
@@ -229,6 +229,31 @@ const buildingsRoutes = require('./routes/buildings');
const adminRoutes = require('./routes/admin');
const mySubjectsRoutes = require('./routes/my_subjects');
// Proxy transparente hacia la API REST de Flask para llamadas AJAX frontend
app.use('/api/v1', async (req, res) => {
try {
const token = req.cookies.auth_token;
const targetUrl = `${process.env.FLASK_API_URL || 'http://localhost:5000/api/v1'}${req.url}`;
const headers = { ...req.headers };
delete headers.host;
if (token && !headers.authorization) {
headers.authorization = `Bearer ${token}`;
}
const resp = await axios({
method: req.method,
url: targetUrl,
data: req.body,
params: req.query,
headers,
validateStatus: () => true
});
return res.status(resp.status).json(resp.data);
} catch (err) {
console.error('API v1 proxy error:', err.message);
return res.status(500).json({ error: 'ProxyError', message: 'Error de comunicación con el backend API: ' + err.message });
}
});
app.use('/', indexRoutes);
app.use('/auth', authRoutes);
app.use('/dashboard', dashboardRoutes);