Skip to content

Commit

Permalink
Use lodas for perf
Browse files Browse the repository at this point in the history
  • Loading branch information
scottcorgan committed May 5, 2014
1 parent 0f6a6c3 commit 06c14da
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
12 changes: 5 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var httpProxy = require('http-proxy');
var _ = require('lodash');
var proxy = httpProxy.createProxyServer({});
var DEFAULT_TIMEOUT = 3000;

Expand All @@ -12,13 +13,10 @@ module.exports = function () {
req.url = req.service.path || req.url; // TODO: test this "OR"

// Set headers
Object
.keys(config.headers || {})
.forEach(function (key) {
req.headers[key.toLowerCase()] =
(req.headers[key.toLowerCase()] || req.service.config.headers[key]);
});

_.each(config.headers, function (val, key) {
req.headers[key.toLowerCase()] =
(req.headers[key.toLowerCase()] || req.service.config.headers[key]);
});

// Set or unset cookies
if (config.cookies === false) delete req.headers.cookie;
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"cookie-parser": "~1.0.1"
},
"dependencies": {
"http-proxy": "~1.1.2"
"http-proxy": "~1.1.2",
"lodash": "^2.4.1"
}
}
13 changes: 13 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ var proxySettings = {
cookies: true
};

/*
var proxySettings = {
task: {
origin: "http://localhost:" + PORT,
headers: {
'Accept': 'application/json'
},
timeout: 30,
cookies: true
}
};
*/

var configSetup = function (req, res, next) {
req.service = {
config: clone(proxySettings)
Expand Down

0 comments on commit 06c14da

Please sign in to comment.