From e54b8c1ea91b08463317734aea96c05c5bcd262e Mon Sep 17 00:00:00 2001 From: Yunjun Mu Date: Fri, 26 Aug 2016 13:57:23 -0400 Subject: [PATCH 1/2] Change http-proxy-middleware logLevel from silent to error --- scripts/start.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/start.js b/scripts/start.js index aa68ab40ff3..f65d8d85cb5 100644 --- a/scripts/start.js +++ b/scripts/start.js @@ -206,7 +206,7 @@ function addMiddleware(devServer) { // of both HTTP and WebSockets to work without false positives. httpProxyMiddleware(pathname => mayProxy.test(pathname), { target: proxy, - logLevel: 'silent', + logLevel: 'error', secure: false, changeOrigin: true }) From 4dd0d43cf05c836f8659606d73762d331aabe266 Mon Sep 17 00:00:00 2001 From: yunjun Date: Fri, 2 Sep 2016 20:54:55 -0400 Subject: [PATCH 2/2] provide onError handler for httpProxyMiddleware --- scripts/start.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/scripts/start.js b/scripts/start.js index f33e08326cf..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. @@ -208,7 +225,8 @@ function addMiddleware(devServer) { // of both HTTP and WebSockets to work without false positives. httpProxyMiddleware(pathname => mayProxy.test(pathname), { target: proxy, - logLevel: 'error', + logLevel: 'silent', + onError: onProxyError(proxy), secure: false, changeOrigin: true })