fix: serve frontend assets over lan
This commit is contained in:
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user