1
1
/*
2
- gzip -middleware.js: Basic example of middleware in node-http-proxy
2
+ urls -middleware.js: Basic example of middleware in node-http-proxy
3
3
4
4
Copyright (c) 2010 Charlie Robbins, Mikeal Rogers, Fedor Indutny, Marak Squires, & Dominic Tarr.
5
5
@@ -30,7 +30,9 @@ var util = require('util'),
30
30
httpProxy = require ( './../lib/node-http-proxy' ) ;
31
31
32
32
//
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.
34
36
//
35
37
function matcher ( url , dest ) {
36
38
var r = new RegExp ( url )
@@ -54,19 +56,19 @@ exports.urls = function (urls) {
54
56
return function ( req , res , next ) {
55
57
//
56
58
// 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)
57
61
//
58
62
var proxy = next ;
59
63
60
64
for ( var k in matchers ) {
61
- var m
65
+ var m ;
62
66
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 ) ;
65
69
}
66
70
}
67
-
68
71
}
69
-
70
72
}
71
73
72
74
httpProxy . createServer (
0 commit comments