Comparing version 2.2.0 to 2.3.0
27
index.js
@@ -14,4 +14,4 @@ delete require.cache[__filename]; | ||
} else if (param instanceof RegExp) { | ||
ret = new RegExp('^' + url.replace(/([\.\-])/g, '\\$1') + '/' + | ||
param.toString().replace(/^\/(\\\/)*|\/$/g, '') + '$'); | ||
ret = new RegExp(url.replace(/([\.\-])/g, '\\$1') + '/' + | ||
param.toString().replace(/^\/(\\\/)*|\/$/g, '')); | ||
} | ||
@@ -28,3 +28,5 @@ return ret; | ||
module.exports = function (options = {}) { | ||
var middleware = express.Router(); | ||
var middleware = express.Router({ | ||
strict: options.strict | ||
}); | ||
var optionControllers = options.controllers || 'controllers'; | ||
@@ -41,3 +43,3 @@ var ctrlDir = path.isAbsolute(optionControllers) ? | ||
var instance = require(file); | ||
var url = file.replace(ctrlDir, '').replace(/\/index$/, '/'); | ||
var url = file.replace(ctrlDir, '').replace(/\/index$/, ''); | ||
@@ -52,3 +54,3 @@ Object.keys(instance).forEach(function (key) { | ||
if (!matcher) { | ||
return console.error('[rainbow]: Router key pattern "%s" is invalid.', key); | ||
return console.warn('[rainbow]: Router key pattern "%s" is invalid.', key); | ||
} | ||
@@ -59,7 +61,7 @@ | ||
if (methods.indexOf(method) === -1 && method !== 'all') { | ||
return console.error('[rainbow]: Unknown HTTP method "%s".', method); | ||
return console.warn('[rainbow]: Unknown HTTP method "%s".', method); | ||
} | ||
if (typeof middleware[method] !== 'function') { | ||
return console.error('[rainbow]: HTTP method "%s" is not supported.', method); | ||
return console.warn('[rainbow]: HTTP method "%s" is not supported.', method); | ||
} | ||
@@ -70,5 +72,10 @@ | ||
var chain = filters.concat(router instanceof Array ? router : [router]); | ||
var params = matcher[2] ? | ||
(matcher[3] ? new RegExp(matcher[3]) : matcher[4]) : | ||
router.params; | ||
var params = router.params; | ||
if (matcher[2]) { | ||
if (matcher[3]) { | ||
params = new RegExp(matcher[3]); | ||
} else { | ||
params = matcher[4]; | ||
} | ||
} | ||
var pathname = joinParam(url, params); | ||
@@ -75,0 +82,0 @@ |
{ | ||
"name": "rainbow", | ||
"description": "Express router middleware for RESTful API base on certain folder path", | ||
"version": "2.2.0", | ||
"version": "2.3.0", | ||
"author": "mytharcher <mytharcher@gmail.com>", | ||
@@ -6,0 +6,0 @@ "main": "index.js", |
@@ -6,3 +6,3 @@ Rainbow | ||
A node [Express][] router middleware for Ajax RESTful API base on certain folder path. | ||
A node [Express][] router middleware for RESTful API base on certain folder path. | ||
@@ -223,2 +223,10 @@ Rainbow mapping all HTTP request route to controllers folder each as path to file as URL. | ||
### Express router options ### | ||
From v2.3.0 rainbow added [express router option](http://expressjs.com/en/api.html#express.router) `strict` into options, default to `false`. | ||
~~~javascript | ||
app.use(rainbow({ strict: true })); | ||
~~~ | ||
Change log | ||
@@ -225,0 +233,0 @@ ---------- |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
17469
12
299
271
1