From a25e84ac1441e1750257259d6c4108aacdd46573 Mon Sep 17 00:00:00 2001 From: Rogee Date: Sun, 20 Sep 2026 15:41:19 +0800 Subject: [PATCH] fix: serve frontend assets over lan --- web/vite.config.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/web/vite.config.ts b/web/vite.config.ts index d019681..3ae8f67 100644 --- a/web/vite.config.ts +++ b/web/vite.config.ts @@ -36,6 +36,23 @@ function creatorHubBuildWarningPlugin(): Plugin { } } +function creatorHubAssetFetchDest(): Plugin { + return { + name: 'creatorhub:asset-fetch-dest', + enforce: 'pre', + configureServer(server) { + server.middlewares.use((request, _response, next) => { + // Chromium can omit Fetch Metadata for LAN requests; Nitro otherwise treats these assets as document routes. + if (request.headers['sec-fetch-dest']) return next() + const pathname = request.url?.split(/[?#]/, 1)[0] ?? '' + if (/\.css$/.test(pathname)) request.headers['sec-fetch-dest'] = 'style' + else if (/\.(?:[cm]?[jt]sx?|mjs)$/.test(pathname)) request.headers['sec-fetch-dest'] = 'script' + next() + }) + } + } +} + function creatorHubApiProxy(): Plugin { const target = process.env.CREATORHUB_CONTROL_PLANE_URL ?? 'http://127.0.0.1:8082' return { @@ -80,6 +97,7 @@ export default defineConfig({ rollupOptions: rollupWarningOptions }, plugins: flattenPlugins([ + creatorHubAssetFetchDest(), creatorHubApiProxy(), tsconfigPaths(), tailwindcss(),