Skip to content

Commit

Permalink
Removing iterate() from middleware module
Browse files Browse the repository at this point in the history
  • Loading branch information
avoidwork committed Oct 8, 2017
1 parent 65a4704 commit 9886881
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions lib/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const path = require("path"),
mime = require("mimetype"),
precise = require("precise"),
regex = require(path.join(__dirname, "regex.js")),
iterate = require(path.join(__dirname, "iterate.js")),
rateHeaders = [
"x-ratelimit-limit",
"x-ratelimit-remaining",
Expand Down Expand Up @@ -90,7 +89,7 @@ function parse (req, res, next) {
const args = req.body ? retsu.chunk(req.body.split(regex.body_split), 2) : [];

req.body = {};
iterate(args, i => {
retsu.each(args, i => {
req.body[i[0]] = coerce(decodeURIComponent(i[1]));
});
} else if (regex.encode_json.test(type) === true || regex.json_wrap.test(req.body) === true) {
Expand Down Expand Up @@ -156,13 +155,15 @@ function keymaster (req, res, next) {
res.send(result);
}
} else {
iterate(routes, (value, key) => {
if (regex.has_param.test(key) === true && regex.leftBrace.test(key) === false) {
key = key.replace(/\/:(\w*)/g, "/(.*)");
retsu.each(Reflect.ownKeys(routes), i => {
let key = i;

if (regex.has_param.test(i) === true && regex.leftBrace.test(i) === false) {
key = i.replace(/\/:(\w*)/g, "/(.*)");
}

if (new RegExp(`^${key}$`, "i").test(uri) === true) {
return !(result = value);
return !(result = routes[i]);
}

return void 0;
Expand Down Expand Up @@ -193,7 +194,7 @@ function rate (req, res, next) {
const results = server.rate(req, config.override),
good = results.shift();

iterate(rateHeaders, (i, idx) => res.header(i, results[idx]));
retsu.each(rateHeaders, (i, idx) => res.header(i, results[idx]));

if (good === true) {
next();
Expand Down Expand Up @@ -300,7 +301,7 @@ function zuul (req, res, next) {
let protectd = false;

if (regex.options.test(req.method) === false) {
iterate(req.server.config.auth.protect, i => {
retsu.each(req.server.config.auth.protect, i => {
if (i.test(uri) === true) {
return !(protectd = true);
}
Expand Down

0 comments on commit 9886881

Please sign in to comment.