File tree 1 file changed +18
-0
lines changed
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) {
170
170
opn ( protocol + '://localhost:' + port + '/' ) ;
171
171
}
172
172
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
+
173
190
function addMiddleware ( devServer ) {
174
191
// `proxy` lets you to specify a fallback server during development.
175
192
// Every unrecognized request will be forwarded to it.
@@ -209,6 +226,7 @@ function addMiddleware(devServer) {
209
226
httpProxyMiddleware ( pathname => mayProxy . test ( pathname ) , {
210
227
target : proxy ,
211
228
logLevel : 'silent' ,
229
+ onError : onProxyError ( proxy ) ,
212
230
secure : false ,
213
231
changeOrigin : true
214
232
} )
You can’t perform that action at this time.
0 commit comments