File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -381,14 +381,22 @@ class Server {
381381 }
382382 }
383383
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
390399 req . url = bypassUrl ;
391-
392400 next ( ) ;
393401 } else if ( proxyMiddleware ) {
394402 return proxyMiddleware ( req , res , next ) ;
Original file line number Diff line number Diff line change @@ -23,6 +23,15 @@ const proxyOptionPathsAsProperties = {
2323 if ( / \. h t m l $ / . test ( req . path ) ) {
2424 return '/index.html' ;
2525 }
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+ }
2635 } ,
2736 } ,
2837} ;
@@ -116,6 +125,10 @@ describe('Proxy', () => {
116125 it ( 'should pass through a proxy when a bypass function returns null' , ( done ) => {
117126 req . get ( '/foo.js' ) . expect ( 200 , / H e y / , done ) ;
118127 } ) ;
128+
129+ it ( 'should not pass through a proxy when a bypass function returns false' , ( done ) => {
130+ req . get ( '/proxyfalse' ) . expect ( 404 , done ) ;
131+ } ) ;
119132 } ) ;
120133 } ) ;
121134
You can’t perform that action at this time.
0 commit comments