website/main.ts

33 lines
890 B
TypeScript

import { App, fsRoutes, staticFiles } from 'fresh'
import { type State } from './utils.ts'
import { contentType } from 'jsr:@std/media-types@1/content-type'
export const app = new App<State>()
app.use(staticFiles())
// temp fix before updating cssBundler middleware
app.use(async (ctx) => {
const response = await ctx.next()
if (response.status === 404 && !response.url.match(/\/chunk-\w+\.js.*/)) {
const ext = ctx.url.pathname.split('.').at(-1) ?? '.bin'
const mime = contentType(ext) ?? 'application/octet-stream'
const file = await Deno.readFile(`./_fresh/static/${ctx.url.pathname}`)
return new Response(file, {
headers: {
'Content-Type': mime,
},
})
}
return response
})
await fsRoutes(app, {
dir: './',
loadIsland: (path) => import(`./islands/${path}`),
loadRoute: (path) => import(`./routes/${path}`),
})
if (import.meta.main) {
await app.listen()
}