File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -121,6 +121,43 @@ async function run () {
121
121
}
122
122
t . ok ( errored )
123
123
} )
124
+
125
+ test ( 'multiple prefixes with multiple plugins' , async ( t ) => {
126
+ const origin2 = Fastify ( )
127
+
128
+ origin2 . get ( '/' , async ( request , reply ) => {
129
+ return 'this is root for origin2'
130
+ } )
131
+
132
+ await origin2 . listen ( 0 )
133
+
134
+ const proxyServer = Fastify ( )
135
+
136
+ // register first proxy on /api
137
+ proxyServer . register ( proxy , {
138
+ upstream : `http://localhost:${ origin . server . address ( ) . port } ` ,
139
+ prefix : '/api'
140
+ } )
141
+
142
+ // register second proxy on /api2
143
+ proxyServer . register ( proxy , {
144
+ upstream : `http://localhost:${ origin2 . server . address ( ) . port } ` ,
145
+ prefix : '/api2'
146
+ } )
147
+
148
+ await proxyServer . listen ( 0 )
149
+
150
+ t . tearDown ( ( ) => {
151
+ origin2 . close ( )
152
+ proxyServer . close ( )
153
+ } )
154
+
155
+ const firstProxyPrefix = await got ( `http://localhost:${ proxyServer . server . address ( ) . port } /api` )
156
+ t . equal ( firstProxyPrefix . body , 'this is root' )
157
+
158
+ const secondProxyPrefix = await got ( `http://localhost:${ proxyServer . server . address ( ) . port } /api2` )
159
+ t . equal ( secondProxyPrefix . body , 'this is root for origin2' )
160
+ } )
124
161
}
125
162
126
163
run ( )
You can’t perform that action at this time.
0 commit comments