Add small bun project
This commit is contained in:
parent
d28cca98aa
commit
80ebab8fd9
5 changed files with 248 additions and 0 deletions
46
index.ts
Normal file
46
index.ts
Normal file
|
@ -0,0 +1,46 @@
|
|||
const fetch = (req: Request) => {
|
||||
const url = new URL(req.url);
|
||||
const path = url.pathname;
|
||||
|
||||
if (path === "/") {
|
||||
return new Response(Bun.file("./index.html"), {
|
||||
headers: {
|
||||
"Content-Type": "text/html"
|
||||
}
|
||||
});
|
||||
} else if (path === "/style.css") {
|
||||
return new Response(Bun.file("./style.css"), {
|
||||
headers: {
|
||||
"Content-Type": "text/css"
|
||||
}
|
||||
});
|
||||
} else if (path === "/cat.gif") {
|
||||
return new Response(Bun.file("./cat.gif"), {
|
||||
headers: {
|
||||
"Content-Type": "image/gif"
|
||||
}
|
||||
});
|
||||
} else if (path === "/favicon.ico") {
|
||||
return new Response(Bun.file("./favicon.ico"), {
|
||||
headers: {
|
||||
"Content-Type": "image/x-icon"
|
||||
}
|
||||
})
|
||||
} else if (path.startsWith('/fonts/')) {
|
||||
const fontPath = path.slice('/fonts/'.length);
|
||||
return new Response(Bun.file(`./fonts/${fontPath}`), {
|
||||
headers: {
|
||||
"Content-Type": "application/octet-stream"
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return new Response("404!");
|
||||
}
|
||||
|
||||
Bun.serve({
|
||||
port: 8888,
|
||||
hostname: "localhost",
|
||||
fetch
|
||||
});
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue