File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -170,6 +170,23 @@ function openBrowser(port, protocol) {
170170 opn ( protocol + '://localhost:' + port + '/' ) ;
171171}
172172
173+ // We need to provide a custom onError function for httpProxyMiddleware.
174+ // It allows us to log custom error messages on the console.
175+ function onProxyError ( proxy ) {
176+ return function ( err , req , res ) {
177+ var host = req . headers && req . headers . host ;
178+ console . log (
179+ chalk . red ( 'Proxy error:' ) + ' Could not proxy request ' + chalk . cyan ( req . url ) +
180+ ' from ' + chalk . cyan ( host ) + ' to ' + chalk . cyan ( proxy ) + '.'
181+ ) ;
182+ console . log (
183+ 'See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (' +
184+ chalk . cyan ( err . code ) + ').'
185+ ) ;
186+ console . log ( ) ;
187+ }
188+ }
189+
173190function addMiddleware ( devServer ) {
174191 // `proxy` lets you to specify a fallback server during development.
175192 // Every unrecognized request will be forwarded to it.
@@ -209,6 +226,7 @@ function addMiddleware(devServer) {
209226 httpProxyMiddleware ( pathname => mayProxy . test ( pathname ) , {
210227 target : proxy ,
211228 logLevel : 'silent' ,
229+ onError : onProxyError ( proxy ) ,
212230 secure : false ,
213231 changeOrigin : true
214232 } )
You can’t perform that action at this time.
0 commit comments