File tree 2 files changed +28
-7
lines changed
2 files changed +28
-7
lines changed Original file line number Diff line number Diff line change @@ -381,14 +381,22 @@ class Server {
381
381
}
382
382
}
383
383
384
- const bypass = typeof proxyConfig . bypass === 'function' ;
385
-
386
- const bypassUrl =
387
- ( bypass && proxyConfig . bypass ( req , res , proxyConfig ) ) || false ;
388
-
389
- if ( bypassUrl ) {
384
+ // - Check if we have a bypass function defined
385
+ // - In case the bypass function is defined we'll retrieve the
386
+ // bypassUrl from it otherwise byPassUrl would be null
387
+ const isByPassFuncDefined =
388
+ typeof proxyConfig . bypass === 'function' ;
389
+ const bypassUrl = isByPassFuncDefined
390
+ ? proxyConfig . bypass ( req , res , proxyConfig )
391
+ : null ;
392
+
393
+ if ( typeof bypassUrl === 'boolean' ) {
394
+ // skip the proxy
395
+ req . url = null ;
396
+ next ( ) ;
397
+ } else if ( typeof bypassUrl === 'string' ) {
398
+ // byPass to that url
390
399
req . url = bypassUrl ;
391
-
392
400
next ( ) ;
393
401
} else if ( proxyMiddleware ) {
394
402
return proxyMiddleware ( req , res , next ) ;
Original file line number Diff line number Diff line change @@ -23,6 +23,15 @@ const proxyOptionPathsAsProperties = {
23
23
if ( / \. h t m l $ / . test ( req . path ) ) {
24
24
return '/index.html' ;
25
25
}
26
+
27
+ return null ;
28
+ } ,
29
+ } ,
30
+ '/proxyfalse' : {
31
+ bypass ( req ) {
32
+ if ( / \/ p r o x y f a l s e $ / . test ( req . path ) ) {
33
+ return false ;
34
+ }
26
35
} ,
27
36
} ,
28
37
} ;
@@ -116,6 +125,10 @@ describe('Proxy', () => {
116
125
it ( 'should pass through a proxy when a bypass function returns null' , ( done ) => {
117
126
req . get ( '/foo.js' ) . expect ( 200 , / H e y / , done ) ;
118
127
} ) ;
128
+
129
+ it ( 'should not pass through a proxy when a bypass function returns false' , ( done ) => {
130
+ req . get ( '/proxyfalse' ) . expect ( 404 , done ) ;
131
+ } ) ;
119
132
} ) ;
120
133
} ) ;
121
134
You can’t perform that action at this time.
0 commit comments