-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.tsx
33 lines (30 loc) · 820 Bytes
/
server.tsx
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
31
32
33
import Elysia from "elysia";
import { hotModuleReload, HotModuleReload } from "elysia-hot-module-reload";
import { renderToReadableStream } from "react-dom/server";
import { App } from "./app";
import { staticPlugin } from "@elysiajs/static";
await Bun.build({
entrypoints: ["./example/client.tsx"],
outdir: "./public",
});
const app = new Elysia()
.get("*", async () => {
const stream = await renderToReadableStream(
<>
<App />
<HotModuleReload />
</>,
{
bootstrapScripts: ["/public/client.js"],
},
);
return new Response(stream, {
headers: { "Content-Type": "text/html" },
});
})
.use(hotModuleReload())
.use(staticPlugin())
.listen(3000);
console.info(
`App is running at http://${app.server?.hostname}:${app.server?.port}`,
);