Skip to content

Commit 69ff694

Browse files
authored
Add Next.js App Router to readme (#57)
* Add Next.js App Router to readme
1 parent be69c41 commit 69ff694

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

packages/trpc-playground/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,29 @@ tRPC Playground provides handlers that serve the playground HTML page and handle
1717
<details>
1818
<summary>Next.js</summary>
1919

20+
Next.js App Router
21+
22+
```ts
23+
// src/app/api/trpc-playground/route.ts
24+
import { appRouter } from '@/server'
25+
import { fetchHandler } from 'trpc-playground/handlers/fetch'
26+
27+
const setupHandler = fetchHandler({
28+
router: appRouter,
29+
trpcApiEndpoint: '/api/trpc',
30+
playgroundEndpoint: '/api/trpc-playground',
31+
})
32+
33+
const handler = async (req: Request) => {
34+
const playgroundHandler = await setupHandler
35+
return await playgroundHandler(req)
36+
}
37+
38+
export { handler as GET, handler as POST }
39+
```
40+
41+
Next.js Pages Router
42+
2043
[Example](https://github.com/sachinraja/trpc-playground/tree/main/apps/next)
2144

2245
```ts

0 commit comments

Comments
 (0)