From ac7aff1b47b0b271d2afb010f3ffd199b9b6685d Mon Sep 17 00:00:00 2001 From: Sean Scally Date: Tue, 24 Jan 2023 19:09:39 -0800 Subject: Add FileSystemRouter + React example (#1894) --- examples/react-file-system-router/index.tsx | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 examples/react-file-system-router/index.tsx (limited to 'examples/react-file-system-router/index.tsx') 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( + + ) + ) + } +} \ No newline at end of file -- cgit v1.2.3