diff --git a/lib/node-http-proxy/routing-proxy.js b/lib/node-http-proxy/routing-proxy.js index e8bc0cfb7..59acaf834 100644 --- a/lib/node-http-proxy/routing-proxy.js +++ b/lib/node-http-proxy/routing-proxy.js @@ -52,6 +52,7 @@ var RoutingProxy = exports.RoutingProxy = function (options) { this.enable = options.enable; this.forward = options.forward; this.changeOrigin = options.changeOrigin || false; + this.notFoundHandler = options.notFoundHandler || false; // // Listen for 'newListener' events so that we can bind 'proxyError' @@ -194,8 +195,13 @@ RoutingProxy.prototype.proxyRequest = function (req, res, options) { // if (!location) { try { - res.writeHead(404); - res.end(); + + if (this.notFoundHandler) { + this.notFoundHandler(req, res); + } else { + res.writeHead(404); + res.end(); + } } catch (er) { console.error("res.writeHead/res.end error: %s", er.message);