KDesktop/index.ts

37 lines
756 B
TypeScript
Raw Permalink Normal View History

2024-06-19 19:46:29 +00:00
const PORT = 3000
Bun.serve({
port: PORT,
async fetch(request, _server) {
const url = new URL(request.url)
if (url.pathname === '/') {
return new Response(Bun.file("./index.html"))
}
if (url.pathname.endsWith(".css")) {
return new Response(Bun.file(`.${url.pathname}`))
}
if (url.pathname.endsWith(".jpg")) {
return new Response(Bun.file(`.${url.pathname}`))
}
const urlPath = `./src/${url.pathname}.js`
const file = Bun.file(urlPath)
if (!(await file.exists())) {
console.log('here: ', urlPath)
return new Response(Bun.file("./404.html"))
}
return new Response(file, {
headers: {
"Content-Type": "text/javascript;charset=UTF-8"
}
})
}
})