File tree Expand file tree Collapse file tree 1 file changed +12
-11
lines changed Expand file tree Collapse file tree 1 file changed +12
-11
lines changed Original file line number Diff line number Diff line change @@ -171,22 +171,23 @@ function Server(compiler, options) {
171171 options . proxy . forEach ( function ( proxyConfig ) {
172172 var bypass = typeof proxyConfig . bypass === 'function' ;
173173 var context = proxyConfig . context || proxyConfig . path ;
174+ var proxyMiddleware ;
175+ // It is possible to use the `bypass` method without a `target`.
176+ // However, the proxy middleware has no use in this case, and will fail to instantiate.
177+ if ( proxyConfig . target ) {
178+ proxyMiddleware = httpProxyMiddleware ( context , proxyConfig ) ;
179+ }
174180
175- function bypassMiddleware ( req , res , next ) {
176- var bypassUrl = proxyConfig . bypass ( req , res , proxyConfig ) || false ;
181+ app . use ( function ( req , res , next ) {
182+ var bypassUrl = bypass && proxyConfig . bypass ( req , res , proxyConfig ) || false ;
177183
178184 if ( bypassUrl ) {
179185 req . url = bypassUrl ;
186+ next ( ) ;
187+ } else if ( proxyMiddleware ) {
188+ return proxyMiddleware ( req , res , next ) ;
180189 }
181-
182- next ( ) ;
183- }
184-
185- if ( bypass ) {
186- app . use ( bypassMiddleware ) ;
187- } else {
188- app . use ( httpProxyMiddleware ( context , proxyConfig ) ) ;
189- }
190+ } ) ;
190191 } ) ;
191192 }
192193 } ,
You can’t perform that action at this time.
0 commit comments