aboutsummaryrefslogtreecommitdiff
path: root/examples/react-file-system-router/index.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'examples/react-file-system-router/index.tsx')
-rw-r--r--examples/react-file-system-router/index.tsx24
1 files changed, 24 insertions, 0 deletions
diff --git a/examples/react-file-system-router/index.tsx b/examples/react-file-system-router/index.tsx
new file mode 100644
index 000000000..a784c393b
--- /dev/null
+++ b/examples/react-file-system-router/index.tsx
@@ -0,0 +1,24 @@
+// A simple way to connect FileSystemRouter to Bun#serve
+// run with `bun run index.tsx`
+
+import { renderToReadableStream } from 'react-dom/server'
+import { FileSystemRouter } from 'bun'
+
+export default {
+ port: 3000,
+ async fetch(request: Request) {
+ const router = new FileSystemRouter({
+ dir: process.cwd() + "/pages",
+ style: "nextjs"
+ })
+
+ const route = router.match(request)
+
+ const { default: Root } = await import(route.filePath)
+ return new Response(
+ await renderToReadableStream(
+ <Root {...route.params} />
+ )
+ )
+ }
+} \ No newline at end of file