aboutsummaryrefslogtreecommitdiff
path: root/bench/react-hello-world/react-hello-world.jsx
blob: ae889f81179e7daf2bcb1b9bdb68cac2ba6daa5b (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
// to run this:
//  NODE_ENV=production bun react-hello-world.jsx

// Make sure you're using react-dom@18.3.0 or later.
// Currently that is available at react-dom@next (which is installed in this repository)
import { renderToReadableStream } from "react-dom/server";
const headers = {
  headers: {
    "Content-Type": "text/html",
  },
};

const App = () => (
  <html>
    <body>
      <h1>Hello World</h1>
      <p>This is an example.</p>
    </body>
  </html>
);

const port = Number(process.env.PORT || 3001);
Bun.serve({
  port,
  async fetch(req) {
    return new Response(await renderToReadableStream(<App />), headers);
  },
});

console.log(`Server running on\n  http://localhost:${port}`);