fix: update temp patch for dynamic css loading

This commit is contained in:
Julien Oculi 2025-05-13 13:26:33 +02:00
parent 245b7b035e
commit 913126b0b0

25
main.ts
View file

@ -5,18 +5,27 @@ import { contentType } from 'jsr:@std/media-types@1/content-type'
export const app = new App<State>() export const app = new App<State>()
app.use(staticFiles()) app.use(staticFiles())
// temp fix before updating cssBundler middleware //TEMP fix before updating cssBundler middleware
app.use(async (ctx) => { app.use(async (ctx) => {
const response = await ctx.next() const response = await ctx.next()
if (response.status === 404 && !response.url.match(/\/chunk-\w+\.js.*/)) { if (
response.status === 404 &&
!ctx.url.pathname.match(/\/js\/[0-9a-f]+\/\S+\.js/)
) {
const ext = ctx.url.pathname.split('.').at(-1) ?? '.bin' const ext = ctx.url.pathname.split('.').at(-1) ?? '.bin'
const mime = contentType(ext) ?? 'application/octet-stream' const mime = contentType(ext) ?? 'application/octet-stream'
const file = await Deno.readFile(`./_fresh/static/${ctx.url.pathname}`)
return new Response(file, { try {
headers: { const file = await Deno.readFile(`./_fresh/static/${ctx.url.pathname}`)
'Content-Type': mime, return new Response(file, {
}, headers: {
}) 'Content-Type': mime,
},
})
} catch {
//TEMP don't handle specific error for now
return response
}
} }
return response return response
}) })