File tree Expand file tree Collapse file tree 3 files changed +26
-1
lines changed
Expand file tree Collapse file tree 3 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -83,6 +83,10 @@ The prefix to mount this plugin on. All the requests to the current server start
8383
8484A ` beforeHandler ` to be applied on all routes. Useful for performing actions before the proxy is executed (e.g. check for authentication).
8585
86+ ### replyOptions
87+
88+ Object with [ reply options] ( https://github.com/fastify/fastify-reply-from#replyfromsource-opts ) for ` fastify-reply-from ` .
89+
8690## Benchmarks
8791
8892The following benchmarks where generated on a Macbook 2018 with i5 and
Original file line number Diff line number Diff line change @@ -27,6 +27,6 @@ module.exports = async function (fastify, opts) {
2727
2828 function reply ( request , reply ) {
2929 var dest = request . req . url . replace ( this . basePath , '' )
30- reply . from ( dest || '/' )
30+ reply . from ( dest || '/' , opts . replyOptions )
3131 }
3232}
Original file line number Diff line number Diff line change @@ -158,6 +158,27 @@ async function run () {
158158 const secondProxyPrefix = await got ( `http://localhost:${ proxyServer . server . address ( ) . port } /api2` )
159159 t . equal ( secondProxyPrefix . body , 'this is root for origin2' )
160160 } )
161+
162+ test ( 'passes replyOptions object to reply.from() calls' , async ( t ) => {
163+ const proxyServer = Fastify ( )
164+
165+ proxyServer . register ( proxy , {
166+ upstream : `http://localhost:${ origin . server . address ( ) . port } ` ,
167+ prefix : '/api' ,
168+ replyOptions : {
169+ rewriteHeaders : headers => Object . assign ( { 'x-test' : 'test' } , headers )
170+ }
171+ } )
172+
173+ await proxyServer . listen ( 0 )
174+
175+ t . tearDown ( ( ) => {
176+ proxyServer . close ( )
177+ } )
178+
179+ const { headers } = await got ( `http://localhost:${ proxyServer . server . address ( ) . port } /api` )
180+ t . match ( headers , { 'x-test' : 'test' } )
181+ } )
161182}
162183
163184run ( )
You can’t perform that action at this time.
0 commit comments