Skip to content

Commit

Permalink
Revert style-only changes
Browse files Browse the repository at this point in the history
  • Loading branch information
pseudomuto committed Sep 30, 2016
1 parent 7f7c2b1 commit 58446c1
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 24 deletions.
28 changes: 17 additions & 11 deletions lib/configproxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,9 @@ ConfigurableProxy.prototype.remove_route = function (path, cb) {
var routes = this._routes;

routes.hasRoute(path, function (result) {
if (result) {
routes.remove(path, cb);
}
if (result) {
routes.remove(path, cb);
}
});
};

Expand All @@ -221,7 +221,7 @@ ConfigurableProxy.prototype.get_routes = function (req, res) {
var inactive_since = null;
if (parsed.query) {
var query = querystring.parse(parsed.query);

if (query.inactive_since !== undefined) {
var timestamp = Date.parse(query.inactive_since);
if (isFinite(timestamp)) {
Expand All @@ -238,16 +238,15 @@ ConfigurableProxy.prototype.get_routes = function (req, res) {
var results = {};

if (inactive_since) {
var keys = Object.keys(routes).filter(function (key) {
return routes[key].last_activity < inactive_since;
Object.keys(routes).forEach(function (path) {
if (routes[path].last_activity < inactive_since) {
results[path] = routes[path];
}
});

keys.forEach(function (key) { results[key] = routes[key]; });
} else {
results = routes;
}


res.write(JSON.stringify(results));
res.end();
that.statsd.increment('api.route.get', 1);
Expand Down Expand Up @@ -300,8 +299,15 @@ ConfigurableProxy.prototype.target_for_req = function (req, cb) {

this._routes.getTarget(base_path + decodeURIComponent(req.url), function (route) {
timer.stop();
var result = route ? { prefix: route.prefix, target: route.data.target } : null;
cb(result);
if (route) {
cb({
prefix: route.prefix,
target: route.data.target
});
return;
}

cb(null);
});
};

Expand Down
7 changes: 1 addition & 6 deletions lib/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,7 @@ function MemoryStore () {
},
update: {
value: function (path, data, cb) {
for (var key in data) {
if (data.hasOwnProperty(key)) {
routes[path][key] = data[key];
}
}

Object.assign(routes[path], data);
this.notify(cb);
}
},
Expand Down
29 changes: 22 additions & 7 deletions test/api_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,16 +181,31 @@ describe("API Tests", function () {
var port = 8998;
var path = '/yesterday';

var now = new Date();
var yesterday = new Date(now.getTime() - (24 * 3.6e6));
var long_ago = new Date(1);
var hour_ago = new Date(now.getTime() - 3.6e6);
var now = new Date();
var yesterday = new Date(now.getTime() - (24 * 3.6e6));
var long_ago = new Date(1);
var hour_ago = new Date(now.getTime() - 3.6e6);
var hour_from_now = new Date(now.getTime() + 3.6e6);

var tests = [
{ name: 'long ago', since: long_ago, expected: {} },
{ name: 'an hour ago', since: hour_ago, expected: { '/yesterday': true } },
{ name: 'the future', since: hour_from_now, expected: { '/yesterday': true, '/today': true } }
{
name: 'long ago',
since: long_ago,
expected: {}
},
{
name: 'an hour ago',
since: hour_ago,
expected: {'/yesterday': true}
},
{
name: 'the future',
since: hour_from_now,
expected: {
'/yesterday': true,
'/today': true
}
}
];

var seen = 0;
Expand Down

0 comments on commit 58446c1

Please sign in to comment.