feat(swdash): Add SW-Dash (Lit-based service worker dashboard), bundle & serve it; improve servertools and static handlers

This commit is contained in:
2025-12-04 13:10:15 +00:00
parent 0f171e43e7
commit 4db6fa6771
15 changed files with 1212 additions and 749 deletions

View File

@@ -1,4 +1,5 @@
import * as plugins from '../plugins.js';
import * as paths from '../paths.js';
/**
* Built-in routes controller for TypedServer
@@ -122,4 +123,25 @@ export class BuiltInRoutesController {
headers: { 'Content-Type': 'text/plain' },
});
}
@plugins.smartserve.Get('/sw-dash/bundle.js')
async getSwDashBundle(ctx: plugins.smartserve.IRequestContext): Promise<Response> {
try {
const bundleContent = (await plugins.fsInstance
.file(paths.swdashBundlePath)
.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 sw-dash bundle:', error);
return new Response('SW-Dash bundle not found', { status: 404 });
}
}
}