aboutsummaryrefslogtreecommitdiff
path: root/bench/react-hello-world/react-hello-world.node.jsx
diff options
context:
space:
mode:
authorGravatar evan <github@evan.lol> 2022-07-12 04:40:12 -0400
committerGravatar GitHub <noreply@github.com> 2022-07-12 01:40:12 -0700
commita9e4ff2029a769737982fcf7e0b7d76d35cf35e4 (patch)
tree497832408d926e2bed779fcec4ba655624a29792 /bench/react-hello-world/react-hello-world.node.jsx
parent7eea306b0ff46a27f134809a9b3c12bf4b38fa7e (diff)
downloadbun-a9e4ff2029a769737982fcf7e0b7d76d35cf35e4.tar.gz
bun-a9e4ff2029a769737982fcf7e0b7d76d35cf35e4.tar.zst
bun-a9e4ff2029a769737982fcf7e0b7d76d35cf35e4.zip
cleanup benchmarks folder (#587)
* cleanup benchmarks * run prettier
Diffstat (limited to 'bench/react-hello-world/react-hello-world.node.jsx')
-rw-r--r--bench/react-hello-world/react-hello-world.node.jsx45
1 files changed, 45 insertions, 0 deletions
diff --git a/bench/react-hello-world/react-hello-world.node.jsx b/bench/react-hello-world/react-hello-world.node.jsx
new file mode 100644
index 000000000..b267bbd4d
--- /dev/null
+++ b/bench/react-hello-world/react-hello-world.node.jsx
@@ -0,0 +1,45 @@
+// 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");
+ res.setHeader("Cache-Control", "no-transform"); // set to match the Deno benchmark, which requires this for an apples to apples comparison
+ 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);