import "dotenv/config"; import { ensureTenant } from "./src/modules/2-identity/db/repo.js"; import { setTenant } from "./src/modules/shared/tenant.js"; import { createApp } from "./src/app.js"; import { ensureBootstrapAdmin } from "./src/modules/auth/services/bootstrap.js"; async function configureUndiciDispatcher() { // Node 18+ usa undici debajo de fetch. Esto suele arreglar timeouts "fantasma" por keep-alive/pooling. try { const { setGlobalDispatcher, Agent } = await import("undici"); setGlobalDispatcher( new Agent({ connections: 10, pipelining: 0, keepAliveTimeout: 10_000, keepAliveMaxTimeout: 10_000, }) ); console.log("[http] undici global dispatcher configured"); } catch (e) { console.warn("[http] undici dispatcher not configured:", e?.message || e); } } const TENANT_KEY = process.env.TENANT_KEY || "piaf"; const port = process.env.PORT || 3000; (async function boot() { await configureUndiciDispatcher(); const tenantId = await ensureTenant({ key: TENANT_KEY, name: TENANT_KEY.toUpperCase() }); setTenant({ id: tenantId, key: TENANT_KEY }); await ensureBootstrapAdmin().catch((err) => console.error("[auth] bootstrap failed:", err)); const app = createApp({ tenantId }); app.listen(port, () => console.log(`UI: http://localhost:${port} (tenant=${TENANT_KEY})`)); })().catch((err) => { console.error("Boot failed:", err); process.exit(1); });