Skip to content

Commit b8005a1

Browse files
committed
adding TS example with cluster support
1 parent 594065d commit b8005a1

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

demos/app.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import http from '../index'
2+
3+
const { router } = http()
4+
5+
router.get('/', (req, res) => {
6+
return new Response()
7+
})
8+
router.get('/:id', async (req) => {
9+
return new Response(req.params.id)
10+
})
11+
router.post('/', async (req) => {
12+
return new Response()
13+
})
14+
15+
Bun.serve({
16+
port: 3000,
17+
reusePort: true,
18+
fetch: router.fetch
19+
})

demos/cluster.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import os from "node:os";
2+
3+
const numCPUs = os.cpus().length;
4+
for (let i = 0; i < numCPUs; i++) {
5+
Bun.spawn(["bun", "app.ts"], {
6+
stdio: ["inherit", "inherit", "inherit"],
7+
env: { ...process.env },
8+
});
9+
}

0 commit comments

Comments
 (0)