Actualizar server.js

This commit is contained in:
2026-11-08 18:51:15 +00:00
parent 38b1d925f3
commit 0f899850be

View File

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