blob: a608f968e866099c35d147720f2229a12fa4888a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
import { file, serve } from "bun";
import "shiki";
import { renderToReadableStream } from "../../test/bun.js/reactdom-bun";
import liveReload from "bun-livereload";
import { join } from "path";
async function fetch(req: Request) {
if (req.url.endsWith("favicon.ico")) {
return new Response("", { status: 404 });
}
if (!req.url.includes(".")) {
const { default: Page } = await import("./page.tsx");
return new Response(await renderToReadableStream(<Page />), {
headers: {
"Content-Type": "text/html",
},
});
}
return new Response(
file(join(import.meta.dir, "./public/", new URL(req.url).pathname))
);
}
serve({
fetch: liveReload(fetch),
port: 8080,
});
|