Skip to content

Commit 4f6ce56

Browse files
Visualizeitdinwwwh
andauthored
docs: simplify tanstack start handlers to use ANY method (#1189)
Replace multiple HTTP method handlers (HEAD, GET, POST, PUT, PATCH, DELETE) with a single ANY handler to simplify the example code. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Documentation** * Updated TanStack Start adapter docs and examples to show simplified route configuration using a single unified handler instead of separate HTTP method handlers. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: unnoq <contact@unnoq.com>
1 parent 3312214 commit 4f6ce56

File tree

3 files changed

+24
-45
lines changed

3 files changed

+24
-45
lines changed

apps/content/docs/adapters/tanstack-start.md

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,17 @@ const handler = new RPCHandler(router, {
2626
],
2727
})
2828

29-
async function handle({ request }: { request: Request }) {
30-
const { response } = await handler.handle(request, {
31-
prefix: '/api/rpc',
32-
context: {}, // Provide initial context if needed
33-
})
34-
35-
return response ?? new Response('Not Found', { status: 404 })
36-
}
37-
3829
export const Route = createFileRoute('/api/rpc/$')({
3930
server: {
4031
handlers: {
41-
HEAD: handle,
42-
GET: handle,
43-
POST: handle,
44-
PUT: handle,
45-
PATCH: handle,
46-
DELETE: handle,
32+
ANY: async ({ request }) => {
33+
const { response } = await handler.handle(request, {
34+
prefix: '/api/rpc',
35+
context: {}, // Provide initial context if needed
36+
})
37+
38+
return response ?? new Response('Not Found', { status: 404 })
39+
},
4740
},
4841
},
4942
})

playgrounds/tanstack-start/src/routes/api/$.ts

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -65,24 +65,17 @@ const handler = new OpenAPIHandler(router, {
6565
],
6666
})
6767

68-
async function handle({ request }: { request: Request }) {
69-
const { response } = await handler.handle(request, {
70-
prefix: '/api',
71-
context: {},
72-
})
73-
74-
return response ?? new Response('Not Found', { status: 404 })
75-
}
76-
7768
export const Route = createFileRoute('/api/$')({
7869
server: {
7970
handlers: {
80-
HEAD: handle,
81-
GET: handle,
82-
POST: handle,
83-
PUT: handle,
84-
PATCH: handle,
85-
DELETE: handle,
71+
ANY: async ({ request }) => {
72+
const { response } = await handler.handle(request, {
73+
prefix: '/api',
74+
context: {},
75+
})
76+
77+
return response ?? new Response('Not Found', { status: 404 })
78+
},
8679
},
8780
},
8881
})

playgrounds/tanstack-start/src/routes/api/rpc.$.ts

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,17 @@ const handler = new RPCHandler(router, {
1717
],
1818
})
1919

20-
async function handle({ request }: { request: Request }) {
21-
const { response } = await handler.handle(request, {
22-
prefix: '/api/rpc',
23-
context: {},
24-
})
25-
26-
return response ?? new Response('Not Found', { status: 404 })
27-
}
28-
2920
export const Route = createFileRoute('/api/rpc/$')({
3021
server: {
3122
handlers: {
32-
HEAD: handle,
33-
GET: handle,
34-
POST: handle,
35-
PUT: handle,
36-
PATCH: handle,
37-
DELETE: handle,
23+
ANY: async ({ request }) => {
24+
const { response } = await handler.handle(request, {
25+
prefix: '/api/rpc',
26+
context: {},
27+
})
28+
29+
return response ?? new Response('Not Found', { status: 404 })
30+
},
3831
},
3932
},
4033
})

0 commit comments

Comments
 (0)