From 0f899850be0ffa4179c5f1c74debabf563446818 Mon Sep 17 00:00:00 2001 From: marsalva Date: Sun, 8 Nov 2026 18:51:15 +0000 Subject: [PATCH] Actualizar server.js --- server.js | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/server.js b/server.js index e416630..931c6d7 100644 --- a/server.js +++ b/server.js @@ -1,3 +1,5 @@ +import { mountIntegraMcp } from './integra-mcp/mount.mjs'; +import { publicBillingSettings } from './integra-mcp/security.mjs'; import express from "express"; import cors from "cors"; import bcrypt from "bcryptjs"; @@ -47,7 +49,8 @@ const corsOptions = { 'http://127.0.0.1:3000' ], methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'], - allowedHeaders: ['Content-Type', 'Authorization'], + allowedHeaders: ['Content-Type', 'Authorization', 'MCP-Protocol-Version'], + exposedHeaders: ['WWW-Authenticate'], credentials: true, optionsSuccessStatus: 200 }; @@ -2710,7 +2713,7 @@ app.get("/public/portal/:token", async (req, res) => { name: qConfig.rows[0]?.full_name || "IntegraRepara", logo: qConfig.rows[0]?.company_logo || null, ad: qConfig.rows[0]?.company_ad || null, - billing_settings: qConfig.rows[0]?.billing_settings || null // AQUÍ VIAJA EL IBAN Y LAS OBSERVACIONES + billing_settings: publicBillingSettings(qConfig.rows[0]?.billing_settings || {}) // AQUÍ VIAJA EL IBAN Y LAS OBSERVACIONES }; // 3. CONSULTA SEGURA (Con o sin ID) @@ -7995,4 +7998,20 @@ app.put("/energy-settings", authMiddleware, async (req, res) => { const port = process.env.PORT || 3000; -autoUpdateDB().then(() => { app.listen(port, "0.0.0.0", () => console.log(`🚀 Server OK en puerto ${port}`)); }); \ No newline at end of file +autoUpdateDB().then(async () => { + if (process.env.INTEGRA_MCP_ENABLED === 'true') { + await mountIntegraMcp({ + app, pool, + // Token interno efímero; nunca se entrega al cliente MCP. + signToken: user => jwt.sign( + { sub: user.id, role: user.role, accountId: user.accountId }, + JWT_SECRET, { expiresIn: '60s' } + ), + checkAvailability: comprobarDisponibilidad + }); + } + app.listen(port, "0.0.0.0", () => console.log(`🚀 Server OK en puerto ${port}`)); +}).catch(error => { + console.error('No se pudo iniciar IntegraRepara:', error.message); + process.exit(1); +}); \ No newline at end of file