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
83
83
84
84
A ` beforeHandler ` to be applied on all routes. Useful for performing actions before the proxy is executed (e.g. check for authentication).
85
85
86
+ ### replyOptions
87
+
88
+ Object with [ reply options] ( https://github.com/fastify/fastify-reply-from#replyfromsource-opts ) for ` fastify-reply-from ` .
89
+
86
90
## Benchmarks
87
91
88
92
The 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) {
27
27
28
28
function reply ( request , reply ) {
29
29
var dest = request . req . url . replace ( this . basePath , '' )
30
- reply . from ( dest || '/' )
30
+ reply . from ( dest || '/' , opts . replyOptions )
31
31
}
32
32
}
Original file line number Diff line number Diff line change @@ -158,6 +158,27 @@ async function run () {
158
158
const secondProxyPrefix = await got ( `http://localhost:${ proxyServer . server . address ( ) . port } /api2` )
159
159
t . equal ( secondProxyPrefix . body , 'this is root for origin2' )
160
160
} )
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
+ } )
161
182
}
162
183
163
184
run ( )
You can’t perform that action at this time.
0 commit comments