Skip to content

Commit f6484de

Browse files
committed
[doc] add comments to examples/url-middleware.js
1 parent 45f3df8 commit f6484de

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

Diff for: examples/url-middleware.js

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
gzip-middleware.js: Basic example of middleware in node-http-proxy
2+
urls-middleware.js: Basic example of middleware in node-http-proxy
33
44
Copyright (c) 2010 Charlie Robbins, Mikeal Rogers, Fedor Indutny, Marak Squires, & Dominic Tarr.
55
@@ -30,7 +30,9 @@ var util = require('util'),
3030
httpProxy = require('./../lib/node-http-proxy');
3131

3232
//
33-
// Basic Http Proxy Server
33+
// url proxying middleware example.
34+
//
35+
// this is not optimised or tested but shows the basic approch to writing a middleware.
3436
//
3537
function matcher (url, dest) {
3638
var r = new RegExp (url)
@@ -54,19 +56,19 @@ exports.urls = function (urls) {
5456
return function (req, res, next) {
5557
//
5658
// in nhp middlewares, `proxy` is the prototype of `next`
59+
// (this means nhp middlewares support both connect API (req, res, next)
60+
// and nhp API (req, res, proxy)
5761
//
5862
var proxy = next;
5963

6064
for (var k in matchers) {
61-
var m
65+
var m;
6266
if (m = matchers[k](req.url)) {
63-
req.url = m.url
64-
return proxy.proxyRequest(req,res, m.dest)
67+
req.url = m.url;
68+
return proxy.proxyRequest(req,res, m.dest);
6569
}
6670
}
67-
6871
}
69-
7072
}
7173

7274
httpProxy.createServer(

0 commit comments

Comments
 (0)