lib/server.js
// Custom onError function for httpProxyMiddleware to log custom error messages on the console.
Custom onError function for httpProxyMiddleware to log custom error messages on the console.
Custom onError function for httpProxyMiddleware to log custom error messages on the console .
function onProxyError(proxy) {
  return function (err, req, res) {
    const 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()
    if (res.writeHead && !res.headersSent) {
      res.writeHead(500)
    }
    res.end('Proxy error: Could not proxy request ' + req.url + ' from ' +
      host + ' to ' + proxy + ' (' + err.code + ').'
    )
  }
}
function onProxyError ( proxy ) { return function ( err , req , res ) { const 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 ( ) if ( res . writeHead && ! res . headersSent ) { res . writeHead ( 500 ) } res . end ( 'Proxy error: Could not proxy request ' + req . url + ' from ' + host + ' to ' + proxy + ' (' + err . code + ').' ) } }
Custom onError function for httpProxyMiddleware to log custom error messages on the console.
Custom onError function for httpProxyMiddleware to log custom error messages on the console .
// And immediately send the proper error response to the client. // Otherwise, the request will eventually timeout with ERR_EMPTY_RESPONSE on the client side.