Added more security and metrics
This commit is contained in:
@@ -1386,6 +1386,9 @@
|
||||
const exportDoxaApiBtn = document.getElementById("exportDoxaApiBtn");
|
||||
const exportOpenApiBtn = document.getElementById("exportOpenApiBtn");
|
||||
const exportSwaggerBtn = document.getElementById("exportSwaggerBtn");
|
||||
const dashboardBtn = document.getElementById("dashboardBtn");
|
||||
const closeDashboard = document.getElementById("closeDashboard");
|
||||
const dashboardPanel = document.getElementById("dashboardPanel");
|
||||
|
||||
importBtn?.addEventListener("click", () => importFile.click());
|
||||
|
||||
@@ -1443,6 +1446,10 @@
|
||||
exportOpenApiBtn?.addEventListener("click", () => download("openapi.json", "openapi.json"));
|
||||
exportSwaggerBtn?.addEventListener("click", () => download("swagger.json", "swagger.json"));
|
||||
|
||||
// Dashboard functionality
|
||||
dashboardBtn?.addEventListener("click", () => openDashboard());
|
||||
closeDashboard?.addEventListener("click", () => closeDashboardPanel());
|
||||
|
||||
const authBtn = document.getElementById("authBtn");
|
||||
authBtn?.addEventListener("click", () => openAuthModal());
|
||||
|
||||
@@ -1578,5 +1585,93 @@
|
||||
return escapeHtml(str);
|
||||
}
|
||||
|
||||
// Dashboard functions
|
||||
async function openDashboard() {
|
||||
const dashboardPanel = document.getElementById("dashboardPanel");
|
||||
const dashboard = document.querySelector(".dashboard-panel");
|
||||
|
||||
if (!dashboardPanel) return;
|
||||
dashboardPanel.style.display = "block";
|
||||
|
||||
try {
|
||||
const res = await fetch("analytics");
|
||||
if (!res.ok) throw new Error("Failed to load analytics");
|
||||
|
||||
const analyticsData = await res.json();
|
||||
updateDashboard(analyticsData);
|
||||
|
||||
// Refresh every 5 seconds
|
||||
if (window.dashboardInterval) clearInterval(window.dashboardInterval);
|
||||
window.dashboardInterval = setInterval(async () => {
|
||||
const res = await fetch("analytics");
|
||||
if (res.ok) {
|
||||
const data = await res.json();
|
||||
updateDashboard(data);
|
||||
}
|
||||
}, 5000);
|
||||
} catch (err) {
|
||||
console.error("Dashboard load error:", err);
|
||||
}
|
||||
}
|
||||
|
||||
function closeDashboardPanel() {
|
||||
const dashboardPanel = document.getElementById("dashboardPanel");
|
||||
if (dashboardPanel) dashboardPanel.style.display = "none";
|
||||
|
||||
if (window.dashboardInterval) {
|
||||
clearInterval(window.dashboardInterval);
|
||||
window.dashboardInterval = null;
|
||||
}
|
||||
}
|
||||
|
||||
function updateDashboard(data) {
|
||||
document.getElementById("totalEndpoints").textContent = data.totalEndpoints || "0";
|
||||
document.getElementById("totalRequests").textContent = data.totalRequests || "0";
|
||||
document.getElementById("totalErrors").textContent = data.totalErrors || "0";
|
||||
document.getElementById("avgResponse").textContent = Math.round((data.averageResponseTime || 0)) + "ms";
|
||||
|
||||
// Update top endpoints
|
||||
const topEndpointsList = (data.topEndpoints || []).map(ep => `
|
||||
<div class="request-item">
|
||||
<div>
|
||||
<span class="request-method">${ep.method}</span>
|
||||
<code style="font-size: 11px; color: var(--text-1);">${ep.path}</code>
|
||||
</div>
|
||||
<div class="request-time">${ep.requestCount} req</div>
|
||||
</div>
|
||||
`).join("") || "<div style='padding: 20px; color: var(--text-2); text-align: center;'>No data yet</div>";
|
||||
|
||||
document.getElementById("topEndpointsChart").innerHTML = `
|
||||
<div style="width: 100%;">
|
||||
<h3 style="margin: 0 0 12px 0; font-size: 13px; font-weight: 600;">Top Endpoints</h3>
|
||||
${topEndpointsList}
|
||||
</div>
|
||||
`;
|
||||
|
||||
// Update recent requests
|
||||
const recentRequestsList = (data.recentRequests || []).map(req => {
|
||||
const statusClass = req.statusCode >= 400 ? "request-status-error" : "request-status-success";
|
||||
return `
|
||||
<div class="request-item">
|
||||
<div>
|
||||
<span class="request-method">${req.method}</span>
|
||||
<code style="font-size: 11px; color: var(--text-1);">${req.path}</code>
|
||||
</div>
|
||||
<div>
|
||||
<span class="request-time ${statusClass}">${req.statusCode}</span>
|
||||
<span class="request-time" style="margin-left: 8px;">${req.responseTimeMs}ms</span>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}).join("") || "<div style='padding: 20px; color: var(--text-2); text-align: center;'>No requests yet</div>";
|
||||
|
||||
document.getElementById("recentRequestsTable").innerHTML = `
|
||||
<div style="padding: 16px; background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius-md);">
|
||||
<h3 style="margin: 0 0 12px 0; font-size: 13px; font-weight: 600;">Recent Requests</h3>
|
||||
${recentRequestsList}
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
init();
|
||||
})();
|
||||
Reference in New Issue
Block a user