@@ -29,8 +29,7 @@ describe('tRPC Adapter Middleware', () => {
2929 input : JSON . stringify ( { '0' : 'Hono' } ) ,
3030 batch : '1' ,
3131 } )
32- const req = new Request ( `http://localhost/trpc/hello?${ searchParams . toString ( ) } ` )
33- const res = await app . request ( req )
32+ const res = await app . request ( `/trpc/hello?${ searchParams . toString ( ) } ` )
3433 expect ( res . status ) . toBe ( 200 )
3534 expect ( await res . json ( ) ) . toEqual ( [
3635 {
@@ -40,4 +39,43 @@ describe('tRPC Adapter Middleware', () => {
4039 } ,
4140 ] )
4241 } )
42+
43+ it ( 'Should auto-detect endpoint from /v1/* route' , async ( ) => {
44+ const app = new Hono ( )
45+ app . use ( '/v1/*' , trpcServer ( { router : appRouter } ) )
46+
47+ const searchParams = new URLSearchParams ( {
48+ input : JSON . stringify ( { '0' : 'World' } ) ,
49+ batch : '1' ,
50+ } )
51+ const res = await app . request ( `/v1/hello?${ searchParams . toString ( ) } ` )
52+ expect ( res . status ) . toBe ( 200 )
53+ expect ( await res . json ( ) ) . toEqual ( [ { result : { data : 'Hello World' } } ] )
54+ } )
55+
56+ it ( 'Should handle short path prefixes like /v/*' , async ( ) => {
57+ const app = new Hono ( )
58+ app . use ( '/v/*' , trpcServer ( { router : appRouter } ) )
59+
60+ const searchParams = new URLSearchParams ( {
61+ input : JSON . stringify ( { '0' : 'Test' } ) ,
62+ batch : '1' ,
63+ } )
64+ const res = await app . request ( `/v/hello?${ searchParams . toString ( ) } ` )
65+ expect ( res . status ) . toBe ( 200 )
66+ expect ( await res . json ( ) ) . toEqual ( [ { result : { data : 'Hello Test' } } ] )
67+ } )
68+
69+ it ( 'Should respect explicit endpoint parameter' , async ( ) => {
70+ const app = new Hono ( )
71+ app . use ( '/api/trpc/*' , trpcServer ( { router : appRouter , endpoint : '/api/trpc' } ) )
72+
73+ const searchParams = new URLSearchParams ( {
74+ input : JSON . stringify ( { '0' : 'Explicit' } ) ,
75+ batch : '1' ,
76+ } )
77+ const res = await app . request ( `/api/trpc/hello?${ searchParams . toString ( ) } ` )
78+ expect ( res . status ) . toBe ( 200 )
79+ expect ( await res . json ( ) ) . toEqual ( [ { result : { data : 'Hello Explicit' } } ] )
80+ } )
4381} )
0 commit comments