fix(optimizer): implementar endpoints POST /api/genetic y proxy Express (v3.8.9)

This commit is contained in:
2026-10-23 17:16:48 -03:00
parent 7da12d90cc
commit e89f1b0457
10 changed files with 395 additions and 25 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "frontend",
"version": "3.8.8",
"version": "3.8.9",
"description": "",
"main": "index.js",
"scripts": {
+32 -4
View File
@@ -86,9 +86,9 @@ const env = nunjucks.configure(path.join(__dirname, '../views'), {
});
// Versiones institucionales del sistema
const APP_VERSION = '3.8.8';
const FRONTEND_VERSION = '3.8.8';
const BACKEND_VERSION = '3.8.8';
const APP_VERSION = '3.8.9';
const FRONTEND_VERSION = '3.8.9';
const BACKEND_VERSION = '3.8.9';
env.addGlobal('app_version', APP_VERSION);
env.addGlobal('frontend_version', FRONTEND_VERSION);
@@ -312,7 +312,7 @@ 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
// Proxy transparente hacia la API REST de FastAPI para llamadas AJAX frontend
app.use('/api/v1', async (req, res) => {
try {
const token = req.cookies.auth_token;
@@ -338,6 +338,34 @@ app.use('/api/v1', async (req, res) => {
}
});
// Proxy transparente hacia la API del Optimizador Genético (/api/genetic)
app.use('/api/genetic', async (req, res) => {
try {
const token = req.cookies.auth_token;
const backendBase = (process.env.FLASK_API_URL || 'http://localhost:5000/api/v1').replace(/\/api\/v1\/?$/, '');
const targetUrl = `${backendBase}/api/genetic${req.url}`;
const headers = { ...req.headers };
delete headers.host;
delete headers['content-length'];
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 genetic proxy error:', err.message);
return res.status(500).json({ error: 'ProxyError', message: 'Error de comunicación con el optimizador genético: ' + err.message });
}
});
app.use('/', indexRoutes);
app.use('/auth', authRoutes);
app.use('/adm', admRoutes);