Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

express-enrouten

Package Overview
Dependencies
Maintainers
3
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-enrouten - npm Package Compare versions

Comparing version 1.1.1 to 1.2.0

coverage/coverage.json

10

index.js

@@ -40,4 +40,8 @@ /*───────────────────────────────────────────────────────────────────────────*\

return function onmount(parent) {
var router;
var router,
routerOptions;
// allow inherited options to be passed to created Routers
routerOptions = options.routerOptions || {};
// Remove sacrificial express app and keep a

@@ -47,3 +51,3 @@ // copy of the currently registered items.

parent._router.stack.pop();
router = registry(app.mountpath);
router = registry(app.mountpath, null, routerOptions);

@@ -58,3 +62,3 @@ // Process the configuration, adding to the stack

options.directory = resolve(options.basedir, options.directory);
directory(router, options.directory);
directory(router, options.directory, routerOptions);
}

@@ -61,0 +65,0 @@

@@ -9,5 +9,5 @@ 'use strict';

module.exports = function directory(router, basedir) {
module.exports = function directory(router, basedir, options) {
var handler;
handler = createFileHandler(router);
handler = createFileHandler(router, options);
traverse(basedir, '', '', handler);

@@ -51,5 +51,6 @@ return router;

* @param router the express Router against which child routers are mounted
* @param options the options object to pass to each express Router created
* @returns {Function} the implementation function to provide to direc`tory
*/
function createFileHandler(router) {
function createFileHandler(router, options) {

@@ -72,3 +73,3 @@ return function handler(basedir, ancestors, current) {

debug('mounting', current, 'at', mountpath);
subrouter = registry(mountpath, router);
subrouter = registry(mountpath, router, options);
impl(subrouter);

@@ -75,0 +76,0 @@ router.use(mountpath, subrouter._router);

@@ -20,3 +20,3 @@ /*jshint proto:true*/

module.exports = function create(mountpath, router) {
module.exports = function create(mountpath, router, options) {
var routes;

@@ -62,3 +62,3 @@

mountpath = mountpath || '/';
router = router || new express.Router();
router = router || new express.Router(options);

@@ -65,0 +65,0 @@ registry.routes = routes || Object.create(null);

@@ -11,3 +11,3 @@ 'use strict';

options.forEach(function (def) {
var method;
var method, middleware;

@@ -17,4 +17,13 @@ assert(def.path, 'path is required');

if (def.middleware) {
assert(Array.isArray(def.middleware), 'middleware must be an array');
def.middleware.forEach(function(mw) {
assert(typeof mw === 'function', 'middleware must be a function');
});
}
method = (def.method || 'get').toLowerCase();
router[method](def.path, def.handler);
middleware = def.middleware || [];
router[method](def.path, middleware, def.handler);
});

@@ -21,0 +30,0 @@ }

{
"name": "express-enrouten",
"version": "1.1.1",
"version": "1.2.0",
"description": "An express route initialization and configuration module.",

@@ -30,13 +30,13 @@ "main": "index.js",

"devDependencies": {
"express": "^4.0.0",
"istanbul": "^0.2.11",
"jshint": "^2.5.1",
"supertest": "^0.13.0",
"tape": "^2.13.3"
"express": "^4.10.3",
"istanbul": "^0.3.2",
"jshint": "^2.5.10",
"supertest": "^0.15.0",
"tape": "^3.0.3"
},
"dependencies": {
"caller": "0.0.1",
"caller": "^1.0.0",
"debuglog": "^1.0.1",
"reverend": "^0.2.0"
"reverend": "^0.3.0"
}
}

@@ -86,7 +86,15 @@ express-enrouten

Optionally, a `middleware` property can be provided to specify an array of middleware `functions`
(with typical `req`, `res` and `next` arguments) for that specific route.
Note that a `handler` has a different function signature than a `controller`. While a
`controller` takes a single argument (a `router`), a `handler` takes the typical
`req` and `res` pair.
```javascript
app.use(enrouten({
routes: [
{ path: '/', method: 'GET', handler: require('./controllers/index') },
{ path: '/foo', method: 'GET', handler: require('./controllers/foo') }
{ path: '/', method: 'GET', handler: require('./routes/index') },
{ path: '/foo', method: 'GET', handler: require('./routes/foo') },
{ path: '/admin', method: 'GET', handler: require('./routes/foo'), middleware: [isAuthenticated] }
]

@@ -96,2 +104,19 @@ }));

#### routerOptions
The `routerOptions` configuration option (optional) allows additional options to be
specified on each Router instance created by `express-enrouten`. Please see the
[Express API documentation](http://expressjs.com/4x/api.html#router) for complete
documentation on each possible option.
```javascript
app.set('case sensitive routing', true);
app.use(enrouten({
directory: 'controllers',
routerOptions: {
caseSensitive: true
}
}));
```
### Named Routes

@@ -156,1 +181,16 @@ For `index` and `directory` configurations there is also support for named routes.

```
## Linting
```bash
$ npm run-script lint
```
## Tests
```bash
$ npm test
```
## Coverage
```bash
$ npm run-script cover && open coverage/lcov-report/index.html
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc