Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Not Found Handler #333

Closed
wants to merge 1 commit into from

3 participants

Breck Yunits Joseph Orbegoso Pea Charlie Robbins
Breck Yunits

What happens when a request comes to the server that does not match a host in the proxy table? Right now, it always responds with a 404.

I added the ability to define a custom function to fire to handle these events.

Please let me know if you think this is an improvement and if you need any tests or formatting changes to include it.

Thanks,
Breck

Breck Yunits breck7 Added Not Found Handler
Added the ability to use a custom function to fire when a request does not match any of the routes in the proxy table.
63f6db6
Joseph Orbegoso Pea

This would be nice to add.

Charlie Robbins indexzero closed this in 3130665
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 13, 2012
  1. Breck Yunits

    Added Not Found Handler

    breck7 authored
    Added the ability to use a custom function to fire when a request does not match any of the routes in the proxy table.
This page is out of date. Refresh to see the latest.
Showing with 8 additions and 2 deletions.
  1. +8 −2 lib/node-http-proxy/routing-proxy.js
10 lib/node-http-proxy/routing-proxy.js
View
@@ -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);
Something went wrong with that request. Please try again.