Commit 5d0bbb38 authored by indexzero's avatar indexzero

[minor dist] Use `pkginfo`. Minor updates to variable scoping in `.createServer()`

parent d8068a83
...@@ -32,9 +32,9 @@ var util = require('util'), ...@@ -32,9 +32,9 @@ var util = require('util'),
maxSockets = 100; maxSockets = 100;
// //
// ### Version 0.5.7 // 5/19/2011 // Expose version information through `pkginfo`.
// //
exports.version = [0, 5, 7]; require('pkginfo')(module, 'version');
// //
// Track our own list of agents internal to `node-http-proxy` // Track our own list of agents internal to `node-http-proxy`
...@@ -113,30 +113,6 @@ exports.getMaxSockets = function () { ...@@ -113,30 +113,6 @@ exports.getMaxSockets = function () {
exports.setMaxSockets = function (value) { exports.setMaxSockets = function (value) {
maxSockets = value; maxSockets = value;
}; };
//
// stack
// adapted from https://github.com/creationix/stack
//
function stack (middlewares, proxy) {
var handle;
middlewares.reverse().forEach(function (layer) {
var child = handle;
var next = function (err) {
if (err) {
throw err;
//return error(req, res, err);
}
child(req, res);
}
next.__proto__ = proxy;
handle = function (req, res) {
layer(req, res, next);
};
});
return handle;
}
// //
// stack // stack
...@@ -185,6 +161,7 @@ exports.createServer = function () { ...@@ -185,6 +161,7 @@ exports.createServer = function () {
proxy, server, proxy, server,
options = {}, options = {},
middleware = [], middleware = [],
handler,
silent; silent;
args.forEach(function (arg) { args.forEach(function (arg) {
...@@ -196,7 +173,7 @@ exports.createServer = function () { ...@@ -196,7 +173,7 @@ exports.createServer = function () {
}; };
}); });
var proxy = new HttpProxy(options); proxy = new HttpProxy(options);
if (port && host) { if (port && host) {
// //
...@@ -232,7 +209,9 @@ exports.createServer = function () { ...@@ -232,7 +209,9 @@ exports.createServer = function () {
handler = callback = stack(middleware, proxy); handler = callback = stack(middleware, proxy);
} }
else if (middleware.length) { else if (middleware.length) {
//do not use middleware code if it's not needed. //
// Do not use middleware code if it's not needed.
//
var h = middleware[0]; var h = middleware[0];
handler = callback = function (req,res) { h(req,res,proxy) }; handler = callback = function (req,res) { h(req,res,proxy) };
} }
...@@ -273,7 +252,6 @@ exports.createServer = function () { ...@@ -273,7 +252,6 @@ exports.createServer = function () {
// to the consumer of the server // to the consumer of the server
// //
server.proxy = proxy; server.proxy = proxy;
return server; return server;
}; };
......
...@@ -15,7 +15,8 @@ ...@@ -15,7 +15,8 @@
"keywords": ["reverse", "proxy", "http"], "keywords": ["reverse", "proxy", "http"],
"dependencies": { "dependencies": {
"colors": "0.x.x", "colors": "0.x.x",
"optimist": "0.2.x" "optimist": "0.2.x",
"pkginfo": "0.2.x"
}, },
"devDependencies": { "devDependencies": {
"request": "1.9.x", "request": "1.9.x",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment