enableDashboard function
Enables debug dashboard
Implementation
void enableDashboard(App app) {
app.use(debugMiddleware());
app.use(websocketDebugMiddleware());
app.route("GET", "/debug/logs", (req, res) async {
res.send(jsonEncode(logs), ContentType.json);
});
app.route("GET", "/debug", (req, res) async {
res.html(
'<html><head><title>Debug Dashboard</title></head><body><h1>Debug Logs</h1><div id="logs"></div><script src="/debug/app.js"></script></body></html>',
);
});
app.route("GET", "/debug/app.js", (req, res) async {
res.send('''
const logsContainer = document.getElementById('logs');
async function fetchLogs() {
const response = await fetch('/debug/logs');
const logs = await response.json();
logsContainer.innerHTML = logs.map(log => `
<div>
<strong>\${log.method}</strong> \${log.uri}<br>
Time: \${log.timestamp}<br>
Response Time: \${log.responseTimeMs || 'Error'}
</div>
`).join('<hr>');
}
setInterval(fetchLogs, 2000);
''', ContentType("application", "javascript"));
});
app.route("GET", "/debug/ws", (req, res) async {
final socket = await WebSocketTransformer.upgrade(req);
debugSockets.add(socket);
socket.add(jsonEncode(logs));
});
}