Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e1310269fe | |||
| 1aadc2da21 | |||
| 37426f0708 | |||
| c124a06bc6 |
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@api.global/typedserver",
|
||||
"version": "7.8.1",
|
||||
"version": "7.8.3",
|
||||
"description": "A TypeScript-based project for easy serving of static files with support for live reloading, compression, and typed requests.",
|
||||
"type": "module",
|
||||
"exports": {
|
||||
|
||||
@@ -203,4 +203,25 @@ export class BuiltInRoutesController {
|
||||
return new Response('SW-Dash bundle not found', { status: 404 });
|
||||
}
|
||||
}
|
||||
|
||||
@plugins.smartserve.Get('/serviceworker.bundle.js')
|
||||
async getServiceWorkerBundle(): Promise<Response> {
|
||||
try {
|
||||
const bundleContent = (await plugins.fsInstance
|
||||
.file(paths.serviceworkerBundlePath)
|
||||
.encoding('utf8')
|
||||
.read()) as string;
|
||||
|
||||
return new Response(bundleContent, {
|
||||
status: 200,
|
||||
headers: {
|
||||
'Content-Type': 'text/javascript',
|
||||
'Cache-Control': 'no-cache',
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Failed to serve serviceworker bundle:', error);
|
||||
return new Response('ServiceWorker bundle not found', { status: 404 });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ export const injectBundleDir = plugins.path.join(packageDir, './dist_ts_web_inje
|
||||
export const injectBundlePath = plugins.path.join(injectBundleDir, './bundle.js');
|
||||
|
||||
export const serviceworkerBundleDir = plugins.path.join(packageDir, './dist_ts_web_serviceworker');
|
||||
export const serviceworkerBundlePath = plugins.path.join(serviceworkerBundleDir, './serviceworker.bundle.js');
|
||||
|
||||
export const swdashBundleDir = plugins.path.join(packageDir, './dist_ts_swdash');
|
||||
export const swdashBundlePath = plugins.path.join(swdashBundleDir, './bundle.js');
|
||||
@@ -34,48 +34,78 @@ export class DashboardGenerator {
|
||||
* - Resource data
|
||||
*/
|
||||
public async serveMetrics(): Promise<Response> {
|
||||
const metrics = getMetricsCollector();
|
||||
const persistentStore = getPersistentStore();
|
||||
await persistentStore.init();
|
||||
const requestLogStore = getRequestLogStore();
|
||||
try {
|
||||
const metrics = getMetricsCollector();
|
||||
const persistentStore = getPersistentStore();
|
||||
await persistentStore.init();
|
||||
const requestLogStore = getRequestLogStore();
|
||||
|
||||
// Get event data
|
||||
const eventResult = await persistentStore.getEventLog({ limit: 50 });
|
||||
const oneHourAgo = Date.now() - 3600000;
|
||||
const eventCountLastHour = await persistentStore.getEventCount(oneHourAgo);
|
||||
// Get event data
|
||||
const eventResult = await persistentStore.getEventLog({ limit: 50 });
|
||||
const oneHourAgo = Date.now() - 3600000;
|
||||
const eventCountLastHour = await persistentStore.getEventCount(oneHourAgo);
|
||||
|
||||
// Build comprehensive initial response
|
||||
const data = {
|
||||
// Core metrics
|
||||
...metrics.getMetrics(),
|
||||
cacheHitRate: metrics.getCacheHitRate(),
|
||||
networkSuccessRate: metrics.getNetworkSuccessRate(),
|
||||
resourceCount: metrics.getResourceCount(),
|
||||
summary: metrics.getSummary(),
|
||||
// Build comprehensive initial response
|
||||
const data = {
|
||||
// Core metrics
|
||||
...metrics.getMetrics(),
|
||||
cacheHitRate: metrics.getCacheHitRate(),
|
||||
networkSuccessRate: metrics.getNetworkSuccessRate(),
|
||||
resourceCount: metrics.getResourceCount(),
|
||||
summary: metrics.getSummary(),
|
||||
|
||||
// Resources data
|
||||
resources: metrics.getCachedResources(),
|
||||
domains: metrics.getDomainStats(),
|
||||
contentTypes: metrics.getContentTypeStats(),
|
||||
// Resources data
|
||||
resources: metrics.getCachedResources(),
|
||||
domains: metrics.getDomainStats(),
|
||||
contentTypes: metrics.getContentTypeStats(),
|
||||
|
||||
// Events data (initial 50)
|
||||
events: eventResult.events,
|
||||
eventTotalCount: eventResult.totalCount,
|
||||
eventCountLastHour,
|
||||
// Events data (initial 50)
|
||||
events: eventResult.events,
|
||||
eventTotalCount: eventResult.totalCount,
|
||||
eventCountLastHour,
|
||||
|
||||
// Request logs data (initial 50)
|
||||
requestLogs: requestLogStore.getEntries({ limit: 50 }),
|
||||
requestTotalCount: requestLogStore.getTotalCount(),
|
||||
requestStats: requestLogStore.getStats(),
|
||||
requestMethods: requestLogStore.getMethods(),
|
||||
};
|
||||
// Request logs data (initial 50)
|
||||
requestLogs: requestLogStore.getEntries({ limit: 50 }),
|
||||
requestTotalCount: requestLogStore.getTotalCount(),
|
||||
requestStats: requestLogStore.getStats(),
|
||||
requestMethods: requestLogStore.getMethods(),
|
||||
};
|
||||
|
||||
return new Response(JSON.stringify(data), {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Cache-Control': 'no-store',
|
||||
},
|
||||
});
|
||||
return new Response(JSON.stringify(data), {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Cache-Control': 'no-store',
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('[SW Dashboard] serveMetrics error:', error);
|
||||
// Return error response with valid JSON structure so client doesn't crash
|
||||
return new Response(JSON.stringify({
|
||||
error: String(error),
|
||||
cache: { hits: 0, misses: 0, errors: 0, bytesServedFromCache: 0, bytesFetched: 0, averageResponseTime: 0 },
|
||||
network: { totalRequests: 0, successfulRequests: 0, failedRequests: 0, timeouts: 0, averageLatency: 0, totalBytesTransferred: 0 },
|
||||
update: { totalChecks: 0, successfulChecks: 0, failedChecks: 0, updatesFound: 0, updatesApplied: 0, lastCheckTimestamp: 0, lastUpdateTimestamp: 0 },
|
||||
connection: { connectedClients: 0, totalConnectionAttempts: 0, successfulConnections: 0, failedConnections: 0 },
|
||||
speedtest: { lastDownloadSpeedMbps: 0, lastUploadSpeedMbps: 0, lastLatencyMs: 0, lastTestTimestamp: 0, testCount: 0, isOnline: false },
|
||||
startTime: Date.now(),
|
||||
uptime: 0,
|
||||
cacheHitRate: 0,
|
||||
networkSuccessRate: 0,
|
||||
resourceCount: 0,
|
||||
events: [],
|
||||
eventTotalCount: 0,
|
||||
eventCountLastHour: 0,
|
||||
requestLogs: [],
|
||||
requestTotalCount: 0,
|
||||
requestStats: { totalRequests: 0, totalResponses: 0, methodCounts: {}, errorCount: 0, avgDurationMs: 0 },
|
||||
requestMethods: [],
|
||||
}), {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Cache-Control': 'no-store',
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user