feat(developer): implementar visor de logs del servidor y terminal web en vivo con sse
This commit is contained in:
@@ -4487,6 +4487,295 @@ body.dark-mode .dev-tab-btn.active {
|
|||||||
color: #ffffff;
|
color: #ffffff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ==========================================================================
|
||||||
|
VISOR DE LOGS DEL SERVIDOR Y TERMINAL WEB EN VIVO (DEVELOPER)
|
||||||
|
========================================================================== */
|
||||||
|
.dev-terminal-wrapper {
|
||||||
|
background: #090d16;
|
||||||
|
border: 1px solid #1e293b;
|
||||||
|
border-radius: 18px;
|
||||||
|
overflow: hidden;
|
||||||
|
box-shadow: 0 10px 35px rgba(0, 0, 0, 0.45);
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dev-terminal-header {
|
||||||
|
background: #0d1322;
|
||||||
|
border-bottom: 1px solid #1e293b;
|
||||||
|
padding: 12px 18px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 12px;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dev-terminal-dots {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 7px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dev-terminal-dot {
|
||||||
|
width: 11px;
|
||||||
|
height: 11px;
|
||||||
|
border-radius: 50%;
|
||||||
|
}
|
||||||
|
.dev-terminal-dot.dot-red { background: #ef4444; }
|
||||||
|
.dev-terminal-dot.dot-yellow { background: #f59e0b; }
|
||||||
|
.dev-terminal-dot.dot-green { background: #10b981; }
|
||||||
|
|
||||||
|
.dev-terminal-title {
|
||||||
|
font-family: ui-monospace, 'SF Mono', 'Cascadia Code', monospace;
|
||||||
|
font-size: 0.82rem;
|
||||||
|
color: #94a3b8;
|
||||||
|
font-weight: 600;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dev-terminal-badge-live {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
background: rgba(16, 185, 129, 0.15);
|
||||||
|
color: #34d399;
|
||||||
|
border: 1px solid rgba(16, 185, 129, 0.3);
|
||||||
|
font-size: 0.72rem;
|
||||||
|
font-weight: 800;
|
||||||
|
padding: 3px 10px;
|
||||||
|
border-radius: 999px;
|
||||||
|
letter-spacing: 0.05em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dev-terminal-badge-live.paused {
|
||||||
|
background: rgba(245, 158, 11, 0.15);
|
||||||
|
color: #fbbf24;
|
||||||
|
border-color: rgba(245, 158, 11, 0.3);
|
||||||
|
}
|
||||||
|
|
||||||
|
.dev-terminal-badge-live .pulse-dot {
|
||||||
|
width: 7px;
|
||||||
|
height: 7px;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: #10b981;
|
||||||
|
box-shadow: 0 0 8px #10b981;
|
||||||
|
animation: terminalDotPulse 1.5s infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dev-terminal-badge-live.paused .pulse-dot {
|
||||||
|
background: #f59e0b;
|
||||||
|
box-shadow: 0 0 8px #f59e0b;
|
||||||
|
animation: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes terminalDotPulse {
|
||||||
|
0% { transform: scale(0.9); opacity: 0.7; }
|
||||||
|
50% { transform: scale(1.3); opacity: 1; }
|
||||||
|
100% { transform: scale(0.9); opacity: 0.7; }
|
||||||
|
}
|
||||||
|
|
||||||
|
.dev-terminal-toolbar {
|
||||||
|
background: #111827;
|
||||||
|
border-bottom: 1px solid #1f293d;
|
||||||
|
padding: 10px 16px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 12px;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dev-terminal-filters {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dev-terminal-filter-btn {
|
||||||
|
background: #1e293b;
|
||||||
|
color: #94a3b8;
|
||||||
|
border: 1px solid #334155;
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 5px 11px;
|
||||||
|
font-size: 0.74rem;
|
||||||
|
font-weight: 700;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.15s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dev-terminal-filter-btn:hover {
|
||||||
|
background: #334155;
|
||||||
|
color: #f1f5f9;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dev-terminal-filter-btn.active {
|
||||||
|
background: #0284c7;
|
||||||
|
color: #ffffff;
|
||||||
|
border-color: #38bdf8;
|
||||||
|
box-shadow: 0 0 10px rgba(2, 132, 199, 0.35);
|
||||||
|
}
|
||||||
|
|
||||||
|
.dev-terminal-actions {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dev-terminal-search-input {
|
||||||
|
background: #0b0f19;
|
||||||
|
border: 1px solid #334155;
|
||||||
|
border-radius: 8px;
|
||||||
|
color: #f1f5f9;
|
||||||
|
font-family: ui-monospace, 'SF Mono', monospace;
|
||||||
|
font-size: 0.76rem;
|
||||||
|
padding: 6px 12px;
|
||||||
|
width: 220px;
|
||||||
|
max-width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dev-terminal-search-input:focus {
|
||||||
|
outline: none;
|
||||||
|
border-color: #38bdf8;
|
||||||
|
box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.dev-terminal-btn {
|
||||||
|
background: #1e293b;
|
||||||
|
color: #e2e8f0;
|
||||||
|
border: 1px solid #334155;
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 5px 10px;
|
||||||
|
font-size: 0.74rem;
|
||||||
|
font-weight: 700;
|
||||||
|
cursor: pointer;
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 5px;
|
||||||
|
transition: all 0.15s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dev-terminal-btn:hover {
|
||||||
|
background: #334155;
|
||||||
|
color: #ffffff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dev-terminal-screen {
|
||||||
|
background: #080c14;
|
||||||
|
height: 520px;
|
||||||
|
max-height: 65vh;
|
||||||
|
overflow-y: auto;
|
||||||
|
padding: 16px 18px;
|
||||||
|
font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', ui-monospace, Menlo, Consolas, monospace;
|
||||||
|
font-size: 0.81rem;
|
||||||
|
line-height: 1.55;
|
||||||
|
color: #cbd5e1;
|
||||||
|
white-space: pre-wrap;
|
||||||
|
word-break: break-all;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dev-terminal-screen::-webkit-scrollbar {
|
||||||
|
width: 8px;
|
||||||
|
}
|
||||||
|
.dev-terminal-screen::-webkit-scrollbar-track {
|
||||||
|
background: #080c14;
|
||||||
|
}
|
||||||
|
.dev-terminal-screen::-webkit-scrollbar-thumb {
|
||||||
|
background: #1e293b;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
.dev-terminal-screen::-webkit-scrollbar-thumb:hover {
|
||||||
|
background: #334155;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dev-log-line {
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-start;
|
||||||
|
gap: 10px;
|
||||||
|
padding: 3px 6px;
|
||||||
|
border-radius: 4px;
|
||||||
|
transition: background 0.1s ease;
|
||||||
|
}
|
||||||
|
.dev-log-line:hover {
|
||||||
|
background: rgba(255, 255, 255, 0.04);
|
||||||
|
}
|
||||||
|
|
||||||
|
.dev-log-time {
|
||||||
|
color: #64748b;
|
||||||
|
flex-shrink: 0;
|
||||||
|
user-select: none;
|
||||||
|
font-size: 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dev-log-tag {
|
||||||
|
flex-shrink: 0;
|
||||||
|
padding: 1px 6px;
|
||||||
|
border-radius: 4px;
|
||||||
|
font-size: 0.68rem;
|
||||||
|
font-weight: 800;
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 0.04em;
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dev-log-tag.tag-http { background: rgba(168, 85, 247, 0.18); color: #c084fc; border: 1px solid rgba(168, 85, 247, 0.3); }
|
||||||
|
.dev-log-tag.tag-sinpe { background: rgba(16, 185, 129, 0.18); color: #34d399; border: 1px solid rgba(16, 185, 129, 0.3); }
|
||||||
|
.dev-log-tag.tag-warn { background: rgba(245, 158, 11, 0.18); color: #fbbf24; border: 1px solid rgba(245, 158, 11, 0.3); }
|
||||||
|
.dev-log-tag.tag-error { background: rgba(239, 68, 68, 0.22); color: #f87171; border: 1px solid rgba(239, 68, 68, 0.4); }
|
||||||
|
.dev-log-tag.tag-auth { background: rgba(249, 115, 22, 0.18); color: #fb923c; border: 1px solid rgba(249, 115, 22, 0.3); }
|
||||||
|
.dev-log-tag.tag-orden { background: rgba(34, 197, 94, 0.18); color: #4ade80; border: 1px solid rgba(34, 197, 94, 0.3); }
|
||||||
|
.dev-log-tag.tag-cron,
|
||||||
|
.dev-log-tag.tag-pm2,
|
||||||
|
.dev-log-tag.tag-sistema { background: rgba(14, 165, 233, 0.18); color: #38bdf8; border: 1px solid rgba(14, 165, 233, 0.3); }
|
||||||
|
.dev-log-tag.tag-app { background: rgba(148, 163, 184, 0.15); color: #cbd5e1; border: 1px solid rgba(148, 163, 184, 0.25); }
|
||||||
|
|
||||||
|
.dev-log-msg {
|
||||||
|
flex: 1;
|
||||||
|
color: #e2e8f0;
|
||||||
|
}
|
||||||
|
.dev-log-line.log-level-error .dev-log-msg { color: #fca5a5; }
|
||||||
|
.dev-log-line.log-level-warn .dev-log-msg { color: #fde68a; }
|
||||||
|
|
||||||
|
.dev-terminal-footer {
|
||||||
|
background: #0d1322;
|
||||||
|
border-top: 1px solid #1e293b;
|
||||||
|
padding: 8px 18px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 12px;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
font-family: ui-monospace, 'SF Mono', monospace;
|
||||||
|
font-size: 0.74rem;
|
||||||
|
color: #64748b;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dev-terminal-prompt {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
color: #38bdf8;
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
|
||||||
|
.terminal-blink {
|
||||||
|
animation: termBlink 1s step-end infinite;
|
||||||
|
}
|
||||||
|
@keyframes termBlink {
|
||||||
|
0%, 100% { opacity: 1; }
|
||||||
|
50% { opacity: 0; }
|
||||||
|
}
|
||||||
|
|
||||||
|
.dev-terminal-telemetry {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
.dev-card-uploader-box {
|
.dev-card-uploader-box {
|
||||||
background: #f8fafc;
|
background: #f8fafc;
|
||||||
border: 2px dashed #cbd5e1;
|
border: 2px dashed #cbd5e1;
|
||||||
|
|||||||
+104
-3
@@ -11,9 +11,9 @@
|
|||||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||||
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
|
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
|
||||||
<meta name="apple-mobile-web-app-title" content="SiboPay">
|
<meta name="apple-mobile-web-app-title" content="SiboPay">
|
||||||
<link rel="preload" href="/css/styles.css?v=19.5" as="style">
|
<link rel="preload" href="/css/styles.css?v=19.6" as="style">
|
||||||
<link rel="preload" href="/js/app.js?v=19.5" as="script">
|
<link rel="preload" href="/js/app.js?v=19.6" as="script">
|
||||||
<link rel="stylesheet" href="/css/styles.css?v=19.5">
|
<link rel="stylesheet" href="/css/styles.css?v=19.6">
|
||||||
<link rel="stylesheet" href="/css/desktop.css?v=2.2">
|
<link rel="stylesheet" href="/css/desktop.css?v=2.2">
|
||||||
<style>
|
<style>
|
||||||
/* Transiciones suaves */
|
/* Transiciones suaves */
|
||||||
@@ -263,6 +263,10 @@
|
|||||||
<svg width="17" height="17" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 19.5v-15A2.5 2.5 0 0 1 6.5 2H20v20H6.5a2.5 2.5 0 0 1-2.5-2.5Z"/><path d="M6 6h10"/><path d="M6 10h10"/><path d="M6 14h6"/></svg>
|
<svg width="17" height="17" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 19.5v-15A2.5 2.5 0 0 1 6.5 2H20v20H6.5a2.5 2.5 0 0 1-2.5-2.5Z"/><path d="M6 6h10"/><path d="M6 10h10"/><path d="M6 14h6"/></svg>
|
||||||
<span>Kardex & Alumnos 360°</span>
|
<span>Kardex & Alumnos 360°</span>
|
||||||
</button>
|
</button>
|
||||||
|
<button class="dev-tab-btn" id="btnDevTabLogs" onclick="switchDevTab('logs')">
|
||||||
|
<svg width="17" height="17" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="4 17 10 11 4 5"/><line x1="12" y1="19" x2="20" y2="19"/></svg>
|
||||||
|
<span>Terminal & Logs en Vivo</span>
|
||||||
|
</button>
|
||||||
</nav>
|
</nav>
|
||||||
</div>
|
</div>
|
||||||
</aside>
|
</aside>
|
||||||
@@ -473,11 +477,17 @@
|
|||||||
<span style="font-size: 0.76rem; color: var(--text-muted);">Respaldos automáticos diarios y descargas manuales</span>
|
<span style="font-size: 0.76rem; color: var(--text-muted);">Respaldos automáticos diarios y descargas manuales</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div style="display: flex; gap: 8px; flex-wrap: wrap;">
|
||||||
|
<button type="button" onclick="switchDevTab('logs')" class="dev-action-btn" style="padding: 9px 16px; font-size: 0.84rem; display: inline-flex; align-items: center; gap: 6px; border-color: #38bdf8; color: #0284c7;" title="Abrir terminal interactiva en vivo">
|
||||||
|
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="4 17 10 11 4 5"/><line x1="12" y1="19" x2="20" y2="19"/></svg>
|
||||||
|
<span>Ver Terminal Web ↗</span>
|
||||||
|
</button>
|
||||||
<button type="button" onclick="ejecutarBackupManualDev()" id="btnDevCrearBackup" class="dev-action-btn dev-action-btn-primary" style="padding: 9px 18px; font-size: 0.84rem; display: inline-flex; align-items: center; gap: 6px;">
|
<button type="button" onclick="ejecutarBackupManualDev()" id="btnDevCrearBackup" class="dev-action-btn dev-action-btn-primary" style="padding: 9px 18px; font-size: 0.84rem; display: inline-flex; align-items: center; gap: 6px;">
|
||||||
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.3" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>
|
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.3" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>
|
||||||
<span>Crear Respaldo Ahora</span>
|
<span>Crear Respaldo Ahora</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div id="devBackupsStatusMsg" style="display: none; padding: 10px 14px; border-radius: 10px; margin-bottom: 14px; font-size: 0.82rem; font-weight: 700;"></div>
|
<div id="devBackupsStatusMsg" style="display: none; padding: 10px 14px; border-radius: 10px; margin-bottom: 14px; font-size: 0.82rem; font-weight: 700;"></div>
|
||||||
|
|
||||||
@@ -924,6 +934,97 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- 8. PESTAÑA: VISOR DE LOGS DEL SERVIDOR Y TERMINAL WEB EN VIVO -->
|
||||||
|
<div id="devTabContentLogs" class="dev-tab-content" style="display: none;">
|
||||||
|
<!-- ENCABEZADO Y TELEMETRÍA SUPERIOR -->
|
||||||
|
<div style="background: var(--card-bg); border: 1.5px solid var(--border); border-radius: 18px; padding: 20px; margin-bottom: 20px; box-shadow: 0 4px 16px rgba(0,0,0,0.04); display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 14px;">
|
||||||
|
<div style="display: flex; align-items: center; gap: 14px;">
|
||||||
|
<div style="width: 46px; height: 46px; border-radius: 12px; background: #0f172a; color: #38bdf8; display: flex; align-items: center; justify-content: center; font-size: 1.35rem; border: 1.5px solid #334155; flex-shrink: 0;">
|
||||||
|
💻
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<div style="display: flex; align-items: center; gap: 10px; flex-wrap: wrap;">
|
||||||
|
<h3 style="margin: 0; font-size: 1.22rem; font-weight: 900; color: var(--text-main);">Terminal Web & Logs en Vivo</h3>
|
||||||
|
<span class="dev-terminal-badge-live" id="devTermStatusBadge"><span class="pulse-dot"></span> EN VIVO</span>
|
||||||
|
</div>
|
||||||
|
<p style="font-size: 0.82rem; color: var(--text-muted); margin: 3px 0 0;">Monitoreo en tiempo real de peticiones HTTP, eventos SINPE Móvil, errores y procesos en el servidor.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="display: flex; gap: 8px; flex-wrap: wrap; align-items: center;">
|
||||||
|
<button type="button" class="dev-action-btn" onclick="toggleDevLogsPause()" id="btnDevLogsPause" title="Pausar o reanudar el flujo en vivo">
|
||||||
|
<span id="devLogsPauseIcon">⏸</span> <span id="devLogsPauseText">Pausar Flujo</span>
|
||||||
|
</button>
|
||||||
|
<button type="button" class="dev-action-btn" onclick="clearDevTerminalScreen()" title="Limpiar la pantalla de la terminal">
|
||||||
|
<span>🧹</span> <span>Limpiar Pantalla</span>
|
||||||
|
</button>
|
||||||
|
<button type="button" class="dev-action-btn" onclick="descargarDevLogs()" title="Descargar registro de logs a un archivo">
|
||||||
|
<span>📥</span> <span>Descargar .log</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- VENTANA PRINCIPAL DE LA TERMINAL WEB -->
|
||||||
|
<div class="dev-terminal-wrapper">
|
||||||
|
<!-- HEADER DE LA TERMINAL -->
|
||||||
|
<div class="dev-terminal-header">
|
||||||
|
<div class="dev-terminal-dots">
|
||||||
|
<div class="dev-terminal-dot dot-red" title="Cerrar"></div>
|
||||||
|
<div class="dev-terminal-dot dot-yellow" title="Minimizar"></div>
|
||||||
|
<div class="dev-terminal-dot dot-green" title="Maximizar"></div>
|
||||||
|
</div>
|
||||||
|
<div class="dev-terminal-title">
|
||||||
|
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="4 17 10 11 4 5"/><line x1="12" y1="19" x2="20" y2="19"/></svg>
|
||||||
|
<span>bash ~ sibopay-server (PM2 #4) [tail -f]</span>
|
||||||
|
</div>
|
||||||
|
<div style="display: flex; align-items: center; gap: 12px; font-size: 0.74rem; color: #94a3b8; font-family: ui-monospace, monospace;">
|
||||||
|
<span>Líneas: <strong id="devTermLineCount" style="color: #38bdf8;">0</strong></span>
|
||||||
|
<span style="color: #475569;">|</span>
|
||||||
|
<span id="devTermUptimeLabel">Uptime: --</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- BARRA DE FILTROS Y BÚSQUEDA -->
|
||||||
|
<div class="dev-terminal-toolbar">
|
||||||
|
<div class="dev-terminal-filters">
|
||||||
|
<button type="button" class="dev-terminal-filter-btn active" data-filter="all" onclick="setDevLogsFilter('all', this)">Todos</button>
|
||||||
|
<button type="button" class="dev-terminal-filter-btn" data-filter="http" onclick="setDevLogsFilter('http', this)">⚡ HTTP</button>
|
||||||
|
<button type="button" class="dev-terminal-filter-btn" data-filter="sinpe" onclick="setDevLogsFilter('sinpe', this)">🏦 SINPE</button>
|
||||||
|
<button type="button" class="dev-terminal-filter-btn" data-filter="warn" onclick="setDevLogsFilter('warn', this)">⚠️ Avisos</button>
|
||||||
|
<button type="button" class="dev-terminal-filter-btn" data-filter="error" onclick="setDevLogsFilter('error', this)">❌ Errores</button>
|
||||||
|
<button type="button" class="dev-terminal-filter-btn" data-filter="sistema" onclick="setDevLogsFilter('sistema', this)">⚙️ Sistema</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="dev-terminal-actions">
|
||||||
|
<input type="text" id="devTermSearchInput" class="dev-terminal-search-input" placeholder="🔍 Filtrar logs (grep)..." oninput="applyDevLogsSearch()">
|
||||||
|
<label style="display: inline-flex; align-items: center; gap: 6px; font-size: 0.74rem; color: #94a3b8; cursor: pointer; user-select: none;">
|
||||||
|
<input type="checkbox" id="devTermAutoScrollCheck" checked style="accent-color: #0284c7;"> Auto-scroll
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- PANTALLA DE CONSOLA / LOGS -->
|
||||||
|
<div id="devTerminalScreen" class="dev-terminal-screen">
|
||||||
|
<div style="color: #64748b; font-style: italic; padding: 12px 6px;">Conectando con el stream del servidor...</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- FOOTER DE ESTADO DE LA TERMINAL -->
|
||||||
|
<div class="dev-terminal-footer">
|
||||||
|
<div class="dev-terminal-prompt">
|
||||||
|
<span>sibopay@server:~$</span>
|
||||||
|
<span class="terminal-blink">_</span>
|
||||||
|
</div>
|
||||||
|
<div class="dev-terminal-telemetry" id="devTermTelemetry">
|
||||||
|
<span>Memoria: <strong id="devTermMemMb" style="color: #f1f5f9;">--</strong></span>
|
||||||
|
<span>·</span>
|
||||||
|
<span>Node: <strong id="devTermNodeVer" style="color: #f1f5f9;">--</strong></span>
|
||||||
|
<span>·</span>
|
||||||
|
<span style="color: #10b981;">● Stream Activo</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -630,6 +630,12 @@ function switchDevTab(tab) {
|
|||||||
if (btn) btn.classList.add('active');
|
if (btn) btn.classList.add('active');
|
||||||
if (content) content.style.display = 'block';
|
if (content) content.style.display = 'block';
|
||||||
inicializarDevKardex();
|
inicializarDevKardex();
|
||||||
|
} else if (tab === 'logs') {
|
||||||
|
const btn = document.getElementById('btnDevTabLogs');
|
||||||
|
const content = document.getElementById('devTabContentLogs');
|
||||||
|
if (btn) btn.classList.add('active');
|
||||||
|
if (content) content.style.display = 'block';
|
||||||
|
initDevLogsTerminal();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -9392,6 +9398,287 @@ window.descargarBackupDev = descargarBackupDev;
|
|||||||
window.cargarBackupsDev = cargarBackupsDev;
|
window.cargarBackupsDev = cargarBackupsDev;
|
||||||
window.ejecutarBackupManualDev = ejecutarBackupManualDev;
|
window.ejecutarBackupManualDev = ejecutarBackupManualDev;
|
||||||
|
|
||||||
|
// ==========================================
|
||||||
|
// VISOR DE LOGS DEL SERVIDOR Y TERMINAL WEB EN VIVO (DEVELOPER)
|
||||||
|
// ==========================================
|
||||||
|
let devLogsEventSource = null;
|
||||||
|
let devLogsList = [];
|
||||||
|
let devLogsFilter = 'all';
|
||||||
|
let devLogsSearchQuery = '';
|
||||||
|
let devLogsPaused = false;
|
||||||
|
|
||||||
|
async function initDevLogsTerminal() {
|
||||||
|
const screen = document.getElementById('devTerminalScreen');
|
||||||
|
if (!screen) return;
|
||||||
|
|
||||||
|
// Cargar datos iniciales
|
||||||
|
try {
|
||||||
|
const res = await fetch('/api/developer/logs?limit=300');
|
||||||
|
if (!res.ok) throw new Error('Error al consultar logs');
|
||||||
|
const data = await res.json();
|
||||||
|
|
||||||
|
devLogsList = data.logs || [];
|
||||||
|
actualizarTelemetriaTerminal(data);
|
||||||
|
renderizarDevLogsPantalla();
|
||||||
|
} catch (err) {
|
||||||
|
if (screen) {
|
||||||
|
screen.innerHTML = `<div style="color: #f87171; padding: 10px;">❌ Error al conectar con el servicio de logs: ${escapeHtml(err.message)}</div>`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Conectar SSE en vivo si no está abierto
|
||||||
|
conectarStreamLogsEnVivo();
|
||||||
|
}
|
||||||
|
|
||||||
|
function conectarStreamLogsEnVivo() {
|
||||||
|
if (devLogsEventSource && devLogsEventSource.readyState !== EventSource.CLOSED) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
devLogsEventSource = new EventSource('/api/developer/logs/stream');
|
||||||
|
|
||||||
|
devLogsEventSource.addEventListener('server_log', (e) => {
|
||||||
|
if (devLogsPaused) return;
|
||||||
|
try {
|
||||||
|
const logEntry = JSON.parse(e.data);
|
||||||
|
devLogsList.push(logEntry);
|
||||||
|
if (devLogsList.length > 800) devLogsList.shift();
|
||||||
|
|
||||||
|
if (logCumpleFiltros(logEntry)) {
|
||||||
|
appendLogLineToScreen(logEntry);
|
||||||
|
}
|
||||||
|
actualizarContadorLineas();
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error parseando server_log:', err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
devLogsEventSource.addEventListener('handshake', () => {
|
||||||
|
actualizarEstadoBadgeTerminal(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
devLogsEventSource.onerror = () => {
|
||||||
|
actualizarEstadoBadgeTerminal(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
devLogsEventSource.onopen = () => {
|
||||||
|
actualizarEstadoBadgeTerminal(true);
|
||||||
|
};
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error iniciando SSE de logs:', err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function logCumpleFiltros(log) {
|
||||||
|
if (devLogsFilter !== 'all') {
|
||||||
|
const filter = devLogsFilter.toLowerCase();
|
||||||
|
const levelMatch = (log.level || '').toLowerCase() === filter;
|
||||||
|
const tagMatch = (log.tag || '').toLowerCase() === filter;
|
||||||
|
if (!levelMatch && !tagMatch) return false;
|
||||||
|
}
|
||||||
|
if (devLogsSearchQuery) {
|
||||||
|
const q = devLogsSearchQuery.toLowerCase();
|
||||||
|
const msgMatch = (log.message || '').toLowerCase().includes(q);
|
||||||
|
const tagMatch = (log.tag || '').toLowerCase().includes(q);
|
||||||
|
if (!msgMatch && !tagMatch) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderizarDevLogsPantalla() {
|
||||||
|
const screen = document.getElementById('devTerminalScreen');
|
||||||
|
if (!screen) return;
|
||||||
|
|
||||||
|
const filtrados = devLogsList.filter(logCumpleFiltros);
|
||||||
|
if (filtrados.length === 0) {
|
||||||
|
screen.innerHTML = `<div style="color: #64748b; font-style: italic; padding: 12px 6px;">No hay eventos registrados que coincidan con los filtros actuales.</div>`;
|
||||||
|
actualizarContadorLineas(0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
screen.innerHTML = filtrados.map(crearHtmlLineaLog).join('');
|
||||||
|
actualizarContadorLineas(filtrados.length);
|
||||||
|
|
||||||
|
const autoScrollCheck = document.getElementById('devTermAutoScrollCheck');
|
||||||
|
if (autoScrollCheck && autoScrollCheck.checked) {
|
||||||
|
screen.scrollTop = screen.scrollHeight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function appendLogLineToScreen(log) {
|
||||||
|
const screen = document.getElementById('devTerminalScreen');
|
||||||
|
if (!screen) return;
|
||||||
|
|
||||||
|
const temp = document.createElement('div');
|
||||||
|
temp.innerHTML = crearHtmlLineaLog(log);
|
||||||
|
const row = temp.firstElementChild;
|
||||||
|
if (row) {
|
||||||
|
screen.appendChild(row);
|
||||||
|
}
|
||||||
|
|
||||||
|
const autoScrollCheck = document.getElementById('devTermAutoScrollCheck');
|
||||||
|
if (autoScrollCheck && autoScrollCheck.checked) {
|
||||||
|
screen.scrollTop = screen.scrollHeight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function crearHtmlLineaLog(log) {
|
||||||
|
const tagClass = getTagCssClass(log.tag, log.level);
|
||||||
|
const levelRowClass = log.level === 'error' ? 'log-level-error' : (log.level === 'warn' ? 'log-level-warn' : '');
|
||||||
|
|
||||||
|
let msgFormatted = escapeHtml(log.message || '');
|
||||||
|
msgFormatted = msgFormatted
|
||||||
|
.replace(/\b(GET)\b/g, '<span style="color: #38bdf8; font-weight: 800;">GET</span>')
|
||||||
|
.replace(/\b(POST)\b/g, '<span style="color: #34d399; font-weight: 800;">POST</span>')
|
||||||
|
.replace(/\b(PUT)\b/g, '<span style="color: #c084fc; font-weight: 800;">PUT</span>')
|
||||||
|
.replace(/\b(DELETE)\b/g, '<span style="color: #f87171; font-weight: 800;">DELETE</span>')
|
||||||
|
.replace(/\b(200|201)\b/g, '<span style="color: #4ade80; font-weight: 700;">$1</span>')
|
||||||
|
.replace(/\b(400|401|403|404)\b/g, '<span style="color: #fbbf24; font-weight: 700;">$1</span>')
|
||||||
|
.replace(/\b(500|502|503)\b/g, '<span style="color: #ef4444; font-weight: 800;">$1</span>');
|
||||||
|
|
||||||
|
return `
|
||||||
|
<div class="dev-log-line ${levelRowClass}">
|
||||||
|
<span class="dev-log-time">[${escapeHtml(log.timestamp || '')}]</span>
|
||||||
|
<span class="dev-log-tag ${tagClass}">${escapeHtml(log.tag || 'APP')}</span>
|
||||||
|
<span class="dev-log-msg">${msgFormatted}</span>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getTagCssClass(tag, level) {
|
||||||
|
const t = (tag || '').toLowerCase();
|
||||||
|
const lvl = (level || '').toLowerCase();
|
||||||
|
if (lvl === 'error' || t === 'error') return 'tag-error';
|
||||||
|
if (lvl === 'warn' || t === 'warn') return 'tag-warn';
|
||||||
|
if (t === 'http') return 'tag-http';
|
||||||
|
if (t === 'sinpe') return 'tag-sinpe';
|
||||||
|
if (t === 'auth') return 'tag-auth';
|
||||||
|
if (t === 'orden') return 'tag-orden';
|
||||||
|
if (t === 'sistema' || t === 'pm2' || t === 'cron') return 'tag-sistema';
|
||||||
|
return 'tag-app';
|
||||||
|
}
|
||||||
|
|
||||||
|
function setDevLogsFilter(filter, btn) {
|
||||||
|
devLogsFilter = filter;
|
||||||
|
document.querySelectorAll('.dev-terminal-filter-btn').forEach(b => b.classList.remove('active'));
|
||||||
|
if (btn) btn.classList.add('active');
|
||||||
|
renderizarDevLogsPantalla();
|
||||||
|
}
|
||||||
|
|
||||||
|
function applyDevLogsSearch() {
|
||||||
|
const input = document.getElementById('devTermSearchInput');
|
||||||
|
devLogsSearchQuery = input ? input.value : '';
|
||||||
|
renderizarDevLogsPantalla();
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleDevLogsPause() {
|
||||||
|
devLogsPaused = !devLogsPaused;
|
||||||
|
const icon = document.getElementById('devLogsPauseIcon');
|
||||||
|
const text = document.getElementById('devLogsPauseText');
|
||||||
|
const badge = document.getElementById('devTermStatusBadge');
|
||||||
|
|
||||||
|
if (devLogsPaused) {
|
||||||
|
if (icon) icon.textContent = '▶';
|
||||||
|
if (text) text.textContent = 'Reanudar Flujo';
|
||||||
|
if (badge) {
|
||||||
|
badge.className = 'dev-terminal-badge-live paused';
|
||||||
|
badge.innerHTML = '<span class="pulse-dot"></span> PAUSADO';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (icon) icon.textContent = '⏸';
|
||||||
|
if (text) text.textContent = 'Pausar Flujo';
|
||||||
|
if (badge) {
|
||||||
|
badge.className = 'dev-terminal-badge-live';
|
||||||
|
badge.innerHTML = '<span class="pulse-dot"></span> EN VIVO';
|
||||||
|
}
|
||||||
|
initDevLogsTerminal();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function clearDevTerminalScreen() {
|
||||||
|
devLogsList = [];
|
||||||
|
const screen = document.getElementById('devTerminalScreen');
|
||||||
|
if (screen) {
|
||||||
|
screen.innerHTML = '<div style="color: #64748b; font-style: italic; padding: 12px 6px;">Pantalla de terminal limpiada. Esperando nuevos eventos...</div>';
|
||||||
|
}
|
||||||
|
actualizarContadorLineas(0);
|
||||||
|
try {
|
||||||
|
await fetch('/api/developer/logs/clear', { method: 'POST' });
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
function descargarDevLogs() {
|
||||||
|
if (devLogsList.length === 0) {
|
||||||
|
if (typeof showToast === 'function') {
|
||||||
|
showToast('No hay registros en la terminal para descargar.', 'warning');
|
||||||
|
} else {
|
||||||
|
alert('No hay registros en la terminal para descargar.');
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const lineas = devLogsList.map(l => `[${l.timestamp}] [${l.tag}] ${l.message}`);
|
||||||
|
const contenido = lineas.join('\n');
|
||||||
|
const blob = new Blob([contenido], { type: 'text/plain;charset=utf-8' });
|
||||||
|
const url = URL.createObjectURL(blob);
|
||||||
|
const a = document.createElement('a');
|
||||||
|
const now = new Date();
|
||||||
|
const fechaStr = `${now.getFullYear()}-${String(now.getMonth()+1).padStart(2,'0')}-${String(now.getDate()).padStart(2,'0')}_${String(now.getHours()).padStart(2,'0')}-${String(now.getMinutes()).padStart(2,'0')}`;
|
||||||
|
a.href = url;
|
||||||
|
a.download = `sibopay-server-logs-${fechaStr}.log`;
|
||||||
|
document.body.appendChild(a);
|
||||||
|
a.click();
|
||||||
|
setTimeout(() => {
|
||||||
|
document.body.removeChild(a);
|
||||||
|
URL.revokeObjectURL(url);
|
||||||
|
}, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
function actualizarTelemetriaTerminal(data) {
|
||||||
|
const uptimeLbl = document.getElementById('devTermUptimeLabel');
|
||||||
|
const memLbl = document.getElementById('devTermMemMb');
|
||||||
|
const nodeLbl = document.getElementById('devTermNodeVer');
|
||||||
|
|
||||||
|
if (data && data.uptimeSeconds !== undefined && uptimeLbl) {
|
||||||
|
const d = Math.floor(data.uptimeSeconds / 86400);
|
||||||
|
const h = Math.floor((data.uptimeSeconds % 86400) / 3600);
|
||||||
|
const m = Math.floor((data.uptimeSeconds % 3600) / 60);
|
||||||
|
const s = data.uptimeSeconds % 60;
|
||||||
|
uptimeLbl.textContent = `Uptime: ${d > 0 ? d + 'd ' : ''}${h}h ${m}m ${s}s`;
|
||||||
|
}
|
||||||
|
if (data && data.memoryMb && memLbl) memLbl.textContent = `${data.memoryMb} MB`;
|
||||||
|
if (data && data.nodeVersion && nodeLbl) nodeLbl.textContent = data.nodeVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
function actualizarContadorLineas(num) {
|
||||||
|
const lbl = document.getElementById('devTermLineCount');
|
||||||
|
if (lbl) {
|
||||||
|
lbl.textContent = String(num !== undefined ? num : devLogsList.length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function actualizarEstadoBadgeTerminal(conectado) {
|
||||||
|
const badge = document.getElementById('devTermStatusBadge');
|
||||||
|
if (!badge) return;
|
||||||
|
if (devLogsPaused) return;
|
||||||
|
|
||||||
|
if (conectado) {
|
||||||
|
badge.className = 'dev-terminal-badge-live';
|
||||||
|
badge.innerHTML = '<span class="pulse-dot"></span> EN VIVO';
|
||||||
|
} else {
|
||||||
|
badge.className = 'dev-terminal-badge-live paused';
|
||||||
|
badge.innerHTML = '<span class="pulse-dot"></span> RECONECTANDO...';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
window.initDevLogsTerminal = initDevLogsTerminal;
|
||||||
|
window.setDevLogsFilter = setDevLogsFilter;
|
||||||
|
window.applyDevLogsSearch = applyDevLogsSearch;
|
||||||
|
window.toggleDevLogsPause = toggleDevLogsPause;
|
||||||
|
window.clearDevTerminalScreen = clearDevTerminalScreen;
|
||||||
|
window.descargarDevLogs = descargarDevLogs;
|
||||||
|
|
||||||
// ==========================================
|
// ==========================================
|
||||||
// DESCARGA DIRECTA DE ARCHIVOS (ANTI POPUP-BLOCKER)
|
// DESCARGA DIRECTA DE ARCHIVOS (ANTI POPUP-BLOCKER)
|
||||||
// ==========================================
|
// ==========================================
|
||||||
|
|||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
// SiboPay PWA Service Worker v19.5 - Ultra Fast Startup & Stale-While-Revalidate
|
// SiboPay PWA Service Worker v19.6 - Ultra Fast Startup & Stale-While-Revalidate
|
||||||
const CACHE_NAME = 'sibopay-v19.5';
|
const CACHE_NAME = 'sibopay-v19.6';
|
||||||
const STATIC_ASSETS = [
|
const STATIC_ASSETS = [
|
||||||
'/',
|
'/',
|
||||||
'/index.html',
|
'/index.html',
|
||||||
|
|||||||
@@ -97,9 +97,135 @@ const compression = require('compression');
|
|||||||
const app = express();
|
const app = express();
|
||||||
const PORT = process.env.PORT || 3030;
|
const PORT = process.env.PORT || 3030;
|
||||||
|
|
||||||
|
// ==========================================
|
||||||
|
// MÓDULO: TERMINAL WEB Y LOGS EN VIVO (DEVELOPER)
|
||||||
|
// ==========================================
|
||||||
|
const MAX_SERVER_LOGS = 600;
|
||||||
|
const serverLogsBuffer = [];
|
||||||
|
const devLogClients = new Set();
|
||||||
|
let logSequenceId = 1;
|
||||||
|
|
||||||
|
function pushServerLog(level, tag, rawMessage, details = null) {
|
||||||
|
const now = new Date();
|
||||||
|
const pad = (n) => String(n).padStart(2, '0');
|
||||||
|
const padMs = (n) => String(n).padStart(3, '0');
|
||||||
|
const timeStr = `${pad(now.getHours())}:${pad(now.getMinutes())}:${pad(now.getSeconds())}.${padMs(now.getMilliseconds())}`;
|
||||||
|
|
||||||
|
const msgStr = typeof rawMessage === 'string' ? rawMessage : JSON.stringify(rawMessage);
|
||||||
|
|
||||||
|
const logEntry = {
|
||||||
|
id: logSequenceId++,
|
||||||
|
timestamp: timeStr,
|
||||||
|
isoTime: now.toISOString(),
|
||||||
|
level: level || 'info', // 'info' | 'warn' | 'error' | 'http' | 'sinpe'
|
||||||
|
tag: tag || 'APP',
|
||||||
|
message: msgStr.trim(),
|
||||||
|
details: details ? String(details) : null
|
||||||
|
};
|
||||||
|
|
||||||
|
serverLogsBuffer.push(logEntry);
|
||||||
|
if (serverLogsBuffer.length > MAX_SERVER_LOGS) {
|
||||||
|
serverLogsBuffer.shift();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (devLogClients.size > 0) {
|
||||||
|
const sseMsg = `event: server_log\ndata: ${JSON.stringify(logEntry)}\n\n`;
|
||||||
|
for (const client of devLogClients) {
|
||||||
|
try {
|
||||||
|
client.write(sseMsg);
|
||||||
|
if (typeof client.flush === 'function') client.flush();
|
||||||
|
} catch (e) {
|
||||||
|
devLogClients.delete(client);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Interceptores de consola seguros (sin recursión)
|
||||||
|
const origConsoleLog = console.log;
|
||||||
|
const origConsoleWarn = console.warn;
|
||||||
|
const origConsoleError = console.error;
|
||||||
|
|
||||||
|
console.log = function(...args) {
|
||||||
|
origConsoleLog.apply(console, args);
|
||||||
|
try {
|
||||||
|
const text = args.map(a => (typeof a === 'object' ? JSON.stringify(a) : String(a))).join(' ');
|
||||||
|
let tag = 'APP';
|
||||||
|
let level = 'info';
|
||||||
|
if (text.includes('[SINPE')) { tag = 'SINPE'; }
|
||||||
|
else if (text.includes('[WebPush')) { tag = 'WEBPUSH'; }
|
||||||
|
else if (text.includes('[PISTOLA')) { tag = 'PISTOLA'; }
|
||||||
|
else if (text.includes('[Seguridad')) { tag = 'AUTH'; }
|
||||||
|
else if (text.includes('[AUTO-EXPIRACION')) { tag = 'CRON'; }
|
||||||
|
pushServerLog(level, tag, text);
|
||||||
|
} catch (e) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
console.warn = function(...args) {
|
||||||
|
origConsoleWarn.apply(console, args);
|
||||||
|
try {
|
||||||
|
const text = args.map(a => (typeof a === 'object' ? JSON.stringify(a) : String(a))).join(' ');
|
||||||
|
pushServerLog('warn', 'WARN', text);
|
||||||
|
} catch (e) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
console.error = function(...args) {
|
||||||
|
origConsoleError.apply(console, args);
|
||||||
|
try {
|
||||||
|
const text = args.map(a => (typeof a === 'object' ? (a && a.stack ? a.stack : JSON.stringify(a)) : String(a))).join(' ');
|
||||||
|
pushServerLog('error', 'ERROR', text);
|
||||||
|
} catch (e) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Cargar historial previo de PM2 si existe en el servidor
|
||||||
|
try {
|
||||||
|
const pm2LogPath = '/root/.pm2/logs/recreopay-out.log';
|
||||||
|
if (fs.existsSync(pm2LogPath)) {
|
||||||
|
const rawContent = fs.readFileSync(pm2LogPath, 'utf8');
|
||||||
|
const recentLines = rawContent.split('\n').filter(Boolean).slice(-40);
|
||||||
|
for (const line of recentLines) {
|
||||||
|
let tag = 'PM2';
|
||||||
|
if (line.includes('[SINPE')) tag = 'SINPE';
|
||||||
|
pushServerLog('info', tag, line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
|
pushServerLog('info', 'SISTEMA', `Terminal Web inicializada (Node ${process.version}, PID ${process.pid})`);
|
||||||
|
|
||||||
// Compresión Gzip de alto rendimiento para HTML, JS, CSS y JSON
|
// Compresión Gzip de alto rendimiento para HTML, JS, CSS y JSON
|
||||||
app.use(compression());
|
app.use(compression());
|
||||||
|
|
||||||
|
// Middleware de trazabilidad de peticiones HTTP en tiempo real para la terminal
|
||||||
|
app.use((req, res, next) => {
|
||||||
|
const p = req.path || '';
|
||||||
|
if (p === '/api/events' || p === '/api/developer/logs/stream' || p.startsWith('/css/') || p.startsWith('/js/') || p.startsWith('/img/') || p.endsWith('.png') || p.endsWith('.ico') || p.endsWith('.json')) {
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (p.startsWith('/api/')) {
|
||||||
|
const start = Date.now();
|
||||||
|
const method = req.method;
|
||||||
|
|
||||||
|
res.on('finish', () => {
|
||||||
|
const duration = Date.now() - start;
|
||||||
|
const status = res.statusCode;
|
||||||
|
let level = 'http';
|
||||||
|
let tag = 'HTTP';
|
||||||
|
if (status >= 500) { level = 'error'; }
|
||||||
|
else if (status >= 400) { level = 'warn'; }
|
||||||
|
|
||||||
|
if (p.includes('/sinpe/')) { tag = 'SINPE'; }
|
||||||
|
else if (p.includes('/ordenes') || p.includes('/pos')) { tag = 'ORDEN'; }
|
||||||
|
else if (p.includes('/login') || p.includes('/auth')) { tag = 'AUTH'; }
|
||||||
|
else if (p.includes('/developer/')) { tag = 'DEV'; }
|
||||||
|
|
||||||
|
pushServerLog(level, tag, `${method} ${p} -> ${status} (${duration}ms)`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
|
||||||
// Initialize DB schema & seed data
|
// Initialize DB schema & seed data
|
||||||
initDatabase();
|
initDatabase();
|
||||||
|
|
||||||
@@ -2277,6 +2403,70 @@ app.get('/api/developer/backups/descargar/:filename', (req, res) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// ==========================================
|
||||||
|
// ENDPOINTS TERMINAL WEB Y LOGS EN VIVO (DEVELOPER)
|
||||||
|
// ==========================================
|
||||||
|
app.get('/api/developer/logs', (req, res) => {
|
||||||
|
try {
|
||||||
|
const limit = Math.min(parseInt(req.query.limit || '300', 10), MAX_SERVER_LOGS);
|
||||||
|
const filterLevel = req.query.level;
|
||||||
|
const filterQuery = (req.query.q || '').toLowerCase().trim();
|
||||||
|
let result = serverLogsBuffer;
|
||||||
|
|
||||||
|
if (filterLevel && filterLevel !== 'all') {
|
||||||
|
result = result.filter(l => l.level === filterLevel || l.tag.toLowerCase() === filterLevel.toLowerCase());
|
||||||
|
}
|
||||||
|
if (filterQuery) {
|
||||||
|
result = result.filter(l => l.message.toLowerCase().includes(filterQuery) || l.tag.toLowerCase().includes(filterQuery));
|
||||||
|
}
|
||||||
|
|
||||||
|
const mem = process.memoryUsage();
|
||||||
|
res.json({
|
||||||
|
logs: result.slice(-limit),
|
||||||
|
totalCount: serverLogsBuffer.length,
|
||||||
|
uptimeSeconds: Math.floor(process.uptime()),
|
||||||
|
memoryMb: (mem.rss / (1024 * 1024)).toFixed(1),
|
||||||
|
heapMb: (mem.heapUsed / (1024 * 1024)).toFixed(1),
|
||||||
|
nodeVersion: process.version,
|
||||||
|
pid: process.pid,
|
||||||
|
activeStreamClients: devLogClients.size
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
res.status(500).json({ error: err.message });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
app.get('/api/developer/logs/stream', (req, res) => {
|
||||||
|
res.setHeader('Content-Type', 'text/event-stream; charset=utf-8');
|
||||||
|
res.setHeader('Cache-Control', 'no-cache, no-transform');
|
||||||
|
res.setHeader('Connection', 'keep-alive');
|
||||||
|
res.setHeader('X-Accel-Buffering', 'no');
|
||||||
|
res.flushHeaders();
|
||||||
|
|
||||||
|
devLogClients.add(res);
|
||||||
|
|
||||||
|
res.write(`event: handshake\ndata: ${JSON.stringify({
|
||||||
|
message: 'Terminal conectada en vivo al servidor',
|
||||||
|
timestamp: new Date().toISOString(),
|
||||||
|
pid: process.pid,
|
||||||
|
nodeVersion: process.version
|
||||||
|
})}\n\n`);
|
||||||
|
|
||||||
|
req.on('close', () => {
|
||||||
|
devLogClients.delete(res);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
app.post('/api/developer/logs/clear', (req, res) => {
|
||||||
|
try {
|
||||||
|
serverLogsBuffer.length = 0;
|
||||||
|
pushServerLog('info', 'TERMINAL', 'Buffer de logs reiniciado manualmente por el desarrollador.');
|
||||||
|
res.json({ success: true, message: 'Terminal de logs limpiada' });
|
||||||
|
} catch (err) {
|
||||||
|
res.status(500).json({ error: err.message });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// ==========================================
|
// ==========================================
|
||||||
// CARGA MASIVA DE ESTUDIANTES (DEVELOPER)
|
// CARGA MASIVA DE ESTUDIANTES (DEVELOPER)
|
||||||
// ==========================================
|
// ==========================================
|
||||||
|
|||||||
Reference in New Issue
Block a user