diff --git a/scripts/start.js b/scripts/start.js index f63057b8be1..a0b01545b5b 100644 --- a/scripts/start.js +++ b/scripts/start.js @@ -170,6 +170,23 @@ function openBrowser(port, protocol) { opn(protocol + '://localhost:' + port + '/'); } +// We need to provide a custom onError function for httpProxyMiddleware. +// It allows us to log custom error messages on the console. +function onProxyError(proxy) { + return function(err, req, res){ + var host = req.headers && req.headers.host; + console.log( + chalk.red('Proxy error:') + ' Could not proxy request ' + chalk.cyan(req.url) + + ' from ' + chalk.cyan(host) + ' to ' + chalk.cyan(proxy) + '.' + ); + console.log( + 'See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (' + + chalk.cyan(err.code) + ').' + ); + console.log(); + } +} + function addMiddleware(devServer) { // `proxy` lets you to specify a fallback server during development. // Every unrecognized request will be forwarded to it. @@ -209,6 +226,7 @@ function addMiddleware(devServer) { httpProxyMiddleware(pathname => mayProxy.test(pathname), { target: proxy, logLevel: 'silent', + onError: onProxyError(proxy), secure: false, changeOrigin: true })