From e0b1f64ccae930a97c463236a0cebbf62772192f Mon Sep 17 00:00:00 2001 From: Clive Chan Date: Sun, 19 Jun 2016 22:54:11 -0400 Subject: [PATCH 1/5] Add notFound function to set respondNotFound callback (#44) --- lib/proxy.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/proxy.js b/lib/proxy.js index 1562e5f..ca3d06e 100644 --- a/lib/proxy.js +++ b/lib/proxy.js @@ -86,7 +86,7 @@ function ReverseProxy(opts){ proxy.web(req, res, {target: target}); } }else{ - notFound(res); + respondNotFound(res); } }); @@ -138,7 +138,7 @@ function ReverseProxy(opts){ if(target){ proxy.web(req, res, {target: target}); }else{ - notFound(res); + respondNotFound(res); } }); @@ -174,7 +174,7 @@ function ReverseProxy(opts){ if(target){ proxy.ws(req, socket, head, {target: target}); }else{ - notFound(socket); + respondNotFound(socket); } } @@ -417,11 +417,18 @@ function getSource(req){ } */ -function notFound(res){ +var respondNotFound = function(res){ res.statusCode = 404; res.write('Not Found'); res.end(); -} +}; + +ReverseProxy.prototype.notFound = function(callback){ + if(typeof callback == "function") + respondNotFound = callback; + else + throw Error('notFound callback is not a function'); +}; // // Redirect to the HTTPS proxy From 6a219df6d11f05bcc2e5752e6f88496ad9a7ce68 Mon Sep 17 00:00:00 2001 From: Clive Chan Date: Mon, 20 Jun 2016 11:45:55 -0400 Subject: [PATCH 2/5] Give notFound both req and res as params --- lib/proxy.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/proxy.js b/lib/proxy.js index ca3d06e..4e72fd8 100644 --- a/lib/proxy.js +++ b/lib/proxy.js @@ -86,7 +86,7 @@ function ReverseProxy(opts){ proxy.web(req, res, {target: target}); } }else{ - respondNotFound(res); + respondNotFound(req, res); } }); @@ -138,7 +138,7 @@ function ReverseProxy(opts){ if(target){ proxy.web(req, res, {target: target}); }else{ - respondNotFound(res); + respondNotFound(req, res); } }); @@ -174,7 +174,7 @@ function ReverseProxy(opts){ if(target){ proxy.ws(req, socket, head, {target: target}); }else{ - respondNotFound(socket); + respondNotFound(req, socket); } } @@ -417,7 +417,7 @@ function getSource(req){ } */ -var respondNotFound = function(res){ +var respondNotFound = function(req, res){ res.statusCode = 404; res.write('Not Found'); res.end(); From 2721b6c64875e84570e184bf65ba1278c8d96457 Mon Sep 17 00:00:00 2001 From: Clive Chan Date: Mon, 20 Jun 2016 12:01:23 -0400 Subject: [PATCH 3/5] update README for notFound --- README.md | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index de25ec8..4330ed8 100644 --- a/README.md +++ b/README.md @@ -289,10 +289,34 @@ __Arguments__ --------------------------------------- + +#### Redbird##notFound(callback) + + Gives Redbird a callback function with two parameters, the ExpressJS request + and response objects, respectively, which will be called when a proxy route is + not found. The default is + +```javascript +function(req, res){ + res.statusCode = 404; + res.write('Not Found'); + res.end(); +}; +``` + +__Arguments__ + +```javascript + src {Function(req,res)} The callback which will be called with the request + and response parameters (from ExpressJS) when a proxy route is not found. +``` + +--------------------------------------- + #### Redbird##close() - Close the proxy stoping all the incoming connections. + Close the proxy, stopping all incoming connections. --------------------------------------- From d364accd91044829565a0d02f32b46092d221964 Mon Sep 17 00:00:00 2001 From: Clive Chan Date: Mon, 20 Jun 2016 12:06:15 -0400 Subject: [PATCH 4/5] Added anchor links, which seems to have been half-set-up already --- README.md | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 4330ed8..010fed4 100644 --- a/README.md +++ b/README.md @@ -218,6 +218,12 @@ var redbird = new require('redbird')({ ##Reference +[constructor](#redbird) +[register](#register) +[unregister](#unregister) +[notFound](#notFound) +[close](#close) + ###Redbird(opts) @@ -295,14 +301,14 @@ __Arguments__ Gives Redbird a callback function with two parameters, the ExpressJS request and response objects, respectively, which will be called when a proxy route is not found. The default is - ```javascript -function(req, res){ - res.statusCode = 404; - res.write('Not Found'); - res.end(); -}; + function(req, res){ + res.statusCode = 404; + res.write('Not Found'); + res.end(); + }; ``` +. __Arguments__ From 97f27c8869fa0accd5580ebdb33205ee0b889885 Mon Sep 17 00:00:00 2001 From: Clive Chan Date: Tue, 21 Jun 2016 09:15:45 -0400 Subject: [PATCH 5/5] Oops, it's just HTTP request/response, not Express --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 010fed4..4e734be 100644 --- a/README.md +++ b/README.md @@ -298,7 +298,7 @@ __Arguments__ #### Redbird##notFound(callback) - Gives Redbird a callback function with two parameters, the ExpressJS request + Gives Redbird a callback function with two parameters, the HTTP request and response objects, respectively, which will be called when a proxy route is not found. The default is ```javascript @@ -313,8 +313,8 @@ __Arguments__ __Arguments__ ```javascript - src {Function(req,res)} The callback which will be called with the request - and response parameters (from ExpressJS) when a proxy route is not found. + src {Function(req, res)} The callback which will be called with the HTTP + request and response objects when a proxy route is not found. ``` ---------------------------------------