Skip to content

Commit 520a453

Browse files
authored
tRPCOptions extends FetchHandlerRequestOptions-ish (#42)
* tRPCOptions extends `FetchHandlerRequestOptions`-ish * nix spaces * add changeset
1 parent 0efd95e commit 520a453

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

.changeset/loud-poems-retire.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@hono/trpc-server': patch
3+
---
4+
5+
`trpcServer` options extends FetchHandlerRequestOptions

packages/trpc-server/src/index.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
import type { AnyRouter } from '@trpc/server'
2+
import type { FetchHandlerRequestOptions} from '@trpc/server/adapters/fetch'
23
import { fetchRequestHandler } from '@trpc/server/adapters/fetch'
34
import type { MiddlewareHandler } from 'hono'
45

5-
type tRPCOptions = {
6-
endpoint?: string
7-
router: AnyRouter
8-
}
6+
type tRPCOptions =
7+
Omit<
8+
FetchHandlerRequestOptions<AnyRouter>,
9+
'req' | 'endpoint'
10+
> & Partial<Pick<FetchHandlerRequestOptions<AnyRouter>, 'endpoint'>>
911

10-
export const trpcServer = ({ router, endpoint = '/trpc' }: tRPCOptions): MiddlewareHandler => {
12+
export const trpcServer = ({ endpoint = '/trpc', ...rest }: tRPCOptions): MiddlewareHandler => {
1113
return async (c) => {
1214
const res = fetchRequestHandler({
13-
endpoint: endpoint,
15+
...rest,
16+
endpoint,
1417
req: c.req,
15-
router: router,
1618
})
1719
return res
1820
}

0 commit comments

Comments
 (0)