File tree Expand file tree Collapse file tree
libs/ts-rest/express/src/lib Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ ---
2+ ' @ts-rest/express ' : patch
3+ ---
4+
5+ Expose request headers in express router
Original file line number Diff line number Diff line change 11import { Express , RequestHandler } from 'express' ;
22import { z , ZodTypeAny } from 'zod' ;
3+ import { IncomingHttpHeaders } from 'http' ;
34import {
45 AppRoute ,
56 AppRouteMutation ,
@@ -25,6 +26,7 @@ type AppRouteQueryImplementation<T extends AppRouteQuery> = (
2526 {
2627 params : PathParams < T > ;
2728 query : T [ 'query' ] extends ZodTypeAny ? z . infer < T [ 'query' ] > : null ;
29+ headers : IncomingHttpHeaders ;
2830 } ,
2931 never
3032 >
@@ -36,6 +38,7 @@ type AppRouteMutationImplementation<T extends AppRouteMutation> = (
3638 params : PathParams < T > ;
3739 query : T [ 'query' ] extends ZodTypeAny ? z . infer < T [ 'query' ] > : never ;
3840 body : T [ 'body' ] extends ZodTypeAny ? z . infer < T [ 'body' ] > : never ;
41+ headers : IncomingHttpHeaders ;
3942 } ,
4043 never
4144 >
@@ -103,6 +106,7 @@ const transformAppRouteQueryImplementation = (
103106 // @ts -expect-error because the decorator shape is any
104107 params : req . params ,
105108 query : req . query ,
109+ headers : req . headers ,
106110 } ) ;
107111
108112 return res . status ( Number ( result . status ) ) . json ( result . body ) ;
@@ -145,6 +149,7 @@ const transformAppRouteMutationImplementation = (
145149 params : req . params ,
146150 body : req . body ,
147151 query : req . query ,
152+ headers : req . headers ,
148153 } ) ;
149154
150155 return res . status ( Number ( result . status ) ) . json ( result . body ) ;
You can’t perform that action at this time.
0 commit comments