Skip to content

Commit 8da4887

Browse files
committed
feat: add backend and gateway server implementations for demo purposes
1 parent e2056c0 commit 8da4887

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

examples/backend.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Backend server
2+
const backendServer = Bun.serve({
3+
port: 3001,
4+
5+
async fetch(req: Request): Promise<Response> {
6+
const url = new URL(req.url)
7+
8+
if (url.pathname === "/users") {
9+
return new Response(JSON.stringify([]), {
10+
headers: { "content-type": "application/json" },
11+
})
12+
}
13+
14+
return new Response("Not Found", { status: 404 })
15+
},
16+
})

examples/gateway.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import createFetchGate from "../index"
2+
import { createSilentLogger } from "../src/logger"
3+
4+
const { proxy } = createFetchGate({
5+
base: "http://127.0.0.1:3001",
6+
logger: createSilentLogger(),
7+
})
8+
9+
// Gateway server
10+
const gatewayServer = Bun.serve({
11+
port: 3000,
12+
13+
async fetch(req: Request): Promise<Response> {
14+
const url = new URL(req.url)
15+
16+
if (url.pathname === "/api/users") {
17+
return proxy(req, "/users")
18+
}
19+
20+
return new Response("Not Found", { status: 404 })
21+
},
22+
})

0 commit comments

Comments
 (0)