mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
41 lines
943 B
JavaScript
41 lines
943 B
JavaScript
// Cloudflare Workers version with export default fetch
|
|
// Run with: workerd serve react-hello-world.workerd.config.capnp
|
|
|
|
// Polyfill MessageChannel for workerd
|
|
if (typeof MessageChannel === 'undefined') {
|
|
globalThis.MessageChannel = class MessageChannel {
|
|
constructor() {
|
|
this.port1 = { onmessage: null, postMessage: () => {} };
|
|
this.port2 = {
|
|
postMessage: (msg) => {
|
|
if (this.port1.onmessage) {
|
|
queueMicrotask(() => this.port1.onmessage({ data: msg }));
|
|
}
|
|
}
|
|
};
|
|
}
|
|
};
|
|
}
|
|
|
|
import React from "react";
|
|
import { renderToReadableStream } from "react-dom/server";
|
|
|
|
const headers = {
|
|
"Content-Type": "text/html",
|
|
};
|
|
|
|
const App = () => (
|
|
<html>
|
|
<body>
|
|
<h1>Hello World</h1>
|
|
<p>This is an example.</p>
|
|
</body>
|
|
</html>
|
|
);
|
|
|
|
export default {
|
|
async fetch(request) {
|
|
return new Response(await renderToReadableStream(<App />), { headers });
|
|
},
|
|
};
|