aboutsummaryrefslogtreecommitdiff
path: root/bench/react-hello-world.node.jsx
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-07-04 18:06:30 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-07-04 18:06:30 -0700
commitab7f57239d65901daf2a45951d267702578d3c67 (patch)
tree76788726131de464352a8ee1ff21638c646a8ba4 /bench/react-hello-world.node.jsx
parenta8221356032cb8e24614b252a2deda1ab494f00e (diff)
downloadbun-ab7f57239d65901daf2a45951d267702578d3c67.tar.gz
bun-ab7f57239d65901daf2a45951d267702578d3c67.tar.zst
bun-ab7f57239d65901daf2a45951d267702578d3c67.zip
[bench] react hello world
Diffstat (limited to '')
-rw-r--r--bench/react-hello-world.node.jsx44
1 files changed, 44 insertions, 0 deletions
diff --git a/bench/react-hello-world.node.jsx b/bench/react-hello-world.node.jsx
new file mode 100644
index 000000000..1f765d4a4
--- /dev/null
+++ b/bench/react-hello-world.node.jsx
@@ -0,0 +1,44 @@
+// react-ssr.tsx
+import { renderToPipeableStream } from "react-dom/server.node";
+import React from "react";
+const http = require("http");
+const App = () => (
+ <html>
+ <body>
+ <h1>Hello World</h1>
+ </body>
+ </html>
+);
+var didError = false;
+http
+ .createServer(function (req, res) {
+ const stream = renderToPipeableStream(<App />, {
+ onShellReady() {
+ // The content above all Suspense boundaries is ready.
+ // If something errored before we started streaming, we set the error code appropriately.
+ res.statusCode = didError ? 500 : 200;
+ res.setHeader("Content-type", "text/html");
+ stream.pipe(res);
+ },
+ onShellError(error) {
+ // Something errored before we could complete the shell so we emit an alternative shell.
+ res.statusCode = 500;
+ res.send(
+ '<!doctype html><p>Loading...</p><script src="clientrender.js"></script>'
+ );
+ },
+ onAllReady() {
+ // If you don't want streaming, use this instead of onShellReady.
+ // This will fire after the entire page content is ready.
+ // You can use this for crawlers or static generation.
+ // res.statusCode = didError ? 500 : 200;
+ // res.setHeader('Content-type', 'text/html');
+ // stream.pipe(res);
+ },
+ onError(err) {
+ didError = true;
+ console.error(err);
+ },
+ });
+ })
+ .listen(9080);