Skip to content

Commit

Permalink
Refactoring keymaster() middleware to use the router Map instead …
Browse files Browse the repository at this point in the history
…of `config` such that all middleware is accounted for, updating `woodland` for no good reason

Fixing an npmjs registry mistake
  • Loading branch information
avoidwork committed Dec 4, 2017
1 parent 53d2f7d commit 1b2a24c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
10 changes: 5 additions & 5 deletions lib/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,28 +132,28 @@ function keymaster (req, res, next) {
// No authentication, or it's already happened
if (req.protect === false || req.protectAsync === false || (req.session !== void 0 && req.isAuthenticated() === true) === true) {
const method = regex.get_rewrite.test(req.method) ? "get" : req.method.toLowerCase(),
routes = req.server.config.routes[method] || {},
routes = req.server.router.middleware.get(method.toUpperCase()) || new Map(),
uri = req.parsed.pathname;
let result;

if (uri in routes) {
result = routes[uri];
if (routes.has(uri)) {
result = routes.get(uri)[0];

if (typeof result === "function") {
result.call(req.server.tenso, req, res);
} else {
res.send(result);
}
} else {
retsu.each(Object.keys(routes), i => {
retsu.each(Array.from(routes.keys()), 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 = routes[i]);
return !(result = routes.get(i)[0]);
}

return void 0;
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "tenso",
"description": "Tensō is an elastic REST API gateway for node.js",
"version": "6.1.2",
"version": "6.1.3",
"homepage": "http://avoidwork.github.io/tenso",
"author": "Jason Mulligan <[email protected]>",
"repository": {
Expand Down Expand Up @@ -50,7 +50,7 @@
"tiny-uuid4": "^1.0.1",
"tiny-xml": "^1.0.6",
"uws": "^8.14.1",
"woodland": "^4.1.1",
"woodland": "^4.2.0",
"yamljs": "^0.3.0"
},
"devDependencies": {
Expand Down

0 comments on commit 1b2a24c

Please sign in to comment.