Skip to content

Commit 5d0bbb3

Browse files
committed
[minor dist] Use pkginfo. Minor updates to variable scoping in .createServer()
1 parent d8068a8 commit 5d0bbb3

File tree

2 files changed

+9
-30
lines changed

2 files changed

+9
-30
lines changed

lib/node-http-proxy.js

+7-29
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ var util = require('util'),
3232
maxSockets = 100;
3333

3434
//
35-
// ### Version 0.5.7 // 5/19/2011
35+
// Expose version information through `pkginfo`.
3636
//
37-
exports.version = [0, 5, 7];
37+
require('pkginfo')(module, 'version');
3838

3939
//
4040
// Track our own list of agents internal to `node-http-proxy`
@@ -113,30 +113,6 @@ exports.getMaxSockets = function () {
113113
exports.setMaxSockets = function (value) {
114114
maxSockets = value;
115115
};
116-
//
117-
// stack
118-
// adapted from https://github.com/creationix/stack
119-
//
120-
121-
function stack (middlewares, proxy) {
122-
var handle;
123-
middlewares.reverse().forEach(function (layer) {
124-
125-
var child = handle;
126-
var next = function (err) {
127-
if (err) {
128-
throw err;
129-
//return error(req, res, err);
130-
}
131-
child(req, res);
132-
}
133-
next.__proto__ = proxy;
134-
handle = function (req, res) {
135-
layer(req, res, next);
136-
};
137-
});
138-
return handle;
139-
}
140116

141117
//
142118
// stack
@@ -185,6 +161,7 @@ exports.createServer = function () {
185161
proxy, server,
186162
options = {},
187163
middleware = [],
164+
handler,
188165
silent;
189166

190167
args.forEach(function (arg) {
@@ -196,7 +173,7 @@ exports.createServer = function () {
196173
};
197174
});
198175

199-
var proxy = new HttpProxy(options);
176+
proxy = new HttpProxy(options);
200177

201178
if (port && host) {
202179
//
@@ -232,7 +209,9 @@ exports.createServer = function () {
232209
handler = callback = stack(middleware, proxy);
233210
}
234211
else if (middleware.length) {
235-
//do not use middleware code if it's not needed.
212+
//
213+
// Do not use middleware code if it's not needed.
214+
//
236215
var h = middleware[0];
237216
handler = callback = function (req,res) { h(req,res,proxy) };
238217
}
@@ -273,7 +252,6 @@ exports.createServer = function () {
273252
// to the consumer of the server
274253
//
275254
server.proxy = proxy;
276-
277255
return server;
278256
};
279257

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"keywords": ["reverse", "proxy", "http"],
1616
"dependencies": {
1717
"colors": "0.x.x",
18-
"optimist": "0.2.x"
18+
"optimist": "0.2.x",
19+
"pkginfo": "0.2.x"
1920
},
2021
"devDependencies": {
2122
"request": "1.9.x",

0 commit comments

Comments
 (0)