aboutsummaryrefslogtreecommitdiff
path: root/examples/react-file-system-router/index.tsx
blob: 2abcc6b7e4f6cfc5209764e1fc97c0b74fbe148e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// 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} />));
  },
};
/e38c5ad2cb13f012227c5b00f1763175?s=13&d=retro' width='13' height='13' alt='Gravatar' /> Alex Lam S.L 2-54/+158 2023-08-04Update import-meta.mdGravatar Jarred Sumner 1-2/+1 2023-08-04Fix incorrect docsGravatar Jarred Sumner 1-2/+3 2023-08-04[types] fix `blob.json()` (#3995)Gravatar Alex Lam S.L 1-4/+4 2023-08-04FFI typo (#3973)Gravatar dave caruso 3-5/+10 2023-08-04Buffer.copy should ignore out-of-range sourceEnd (#3971)Gravatar Yifei Wang 2-17/+34 2023-08-04[install] store resolved workspace path in lockfile (#3974)Gravatar Alex Lam S.L 5-82/+187 2023-08-04Fix types (#3963)Gravatar Colin McDonnell 14-274/+892 2023-08-04feat(hot-clear-screen): clear terminal on hot reload (#3976)Gravatar simylein 1-0/+7