From 1aadc2da21c2e37052809cf30c59e4fdeda6df39 Mon Sep 17 00:00:00 2001 From: Juergen Kunz Date: Thu, 4 Dec 2025 20:56:16 +0000 Subject: [PATCH] feat(serviceworker): Add endpoint to serve serviceworker bundle with error handling --- ts/controllers/controller.builtin.ts | 21 +++++++++++++++++++++ ts/paths.ts | 1 + 2 files changed, 22 insertions(+) diff --git a/ts/controllers/controller.builtin.ts b/ts/controllers/controller.builtin.ts index aeb22a2..143761f 100644 --- a/ts/controllers/controller.builtin.ts +++ b/ts/controllers/controller.builtin.ts @@ -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 { + 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 }); + } + } } diff --git a/ts/paths.ts b/ts/paths.ts index ecf8acd..808037f 100644 --- a/ts/paths.ts +++ b/ts/paths.ts @@ -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'); \ No newline at end of file