Comparing version 0.4.0 to 0.5.0
54
index.js
@@ -27,23 +27,24 @@ var approot = process.env.PWD; | ||
exports.route = function (app, paths) { | ||
function route (app, method, url, router) { | ||
var filters = (router.filters || []).map(function (item) { | ||
switch(typeof item) { | ||
case 'function': | ||
return item; | ||
function route (url, method, instance) { | ||
var router = instance[method.toLowerCase()] || instance[method.toUpperCase()]; | ||
case 'string': | ||
return require(path.join(fltrDir, item)); | ||
if (router) { | ||
if (instance[method.toLowerCase()]) { | ||
console.warn('[rainbow]: Lower case HTTP methods are deprecated. Please change "' + method + '" in file:' + file + ' to upper case.'); | ||
} | ||
default: | ||
console.log('[rainbow]: Filter only support function or string of path.'); | ||
return null; | ||
} | ||
}).filter(function (item) { | ||
return !!item; | ||
}); | ||
app[method.toLowerCase()].apply(app, [joinParam(url, router.params)] | ||
.concat(filters) | ||
.concat([router]) | ||
); | ||
var filters = (instance[filters] || []).concat(router.filters || []).map(function (item) { | ||
return ({ | ||
'function': item, | ||
'string': require(path.join(fltrDir, item)) | ||
})[typeof item]; | ||
}).filter(function (item) { | ||
return !!item; | ||
}); | ||
app[method.toLowerCase()].apply(app, [joinParam(url, router.params)] | ||
.concat(filters) | ||
.concat([router]) | ||
); | ||
} | ||
} | ||
@@ -57,18 +58,11 @@ | ||
file = file.replace(/\.[^.]*$/, ''); | ||
var router = require(file); | ||
var single = typeof router == 'function'; | ||
var instance = require(file); | ||
var single = typeof instance == 'function'; | ||
var url = file.replace(ctrlDir, '').replace(/\/index$/, '/'); | ||
single ? route(app, 'all', url, router) : | ||
single ? route(url, 'ALL', {ALL: instance}) : | ||
methods.forEach(function (method) { | ||
var eachRouter = router[method.toLowerCase()] || router[method.toUpperCase()]; | ||
if (eachRouter) { | ||
if (router[method.toLowerCase()]) { | ||
console.log('[rainbow]: Lower case HTTP methods are deprecated. Please change "' + method + '" in file:' + file + ' to upper case.'); | ||
} | ||
route(app, method, url, eachRouter); | ||
} | ||
route(url, method, instance); | ||
}); | ||
}); | ||
}; |
{ | ||
"name": "rainbow", | ||
"description": "Express router middleware for RESTful API base on certain folder path", | ||
"version": "0.4.0", | ||
"version": "0.5.0", | ||
"author": "mytharcher <mytharcher@gmail.com>", | ||
@@ -6,0 +6,0 @@ "main" : "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6828
56
1