README
v50-router
v50-router provides easy to use executable configuration loading. The configuration will load policies, validation, and index functions for execution.
Configuration can be used in such cases:
- Attach to REST API.
- Internal API to execute code inside node process.
- Create API configuration for serverless architecture.
The configuration will create an object, containing:
controller name > action name > array with functions to execute in order
File structure example
└───controllers
├───session
│ ├───add
│ └───delete
└───user
├───login
└───logout
Installation
npm -i --save v50-router
API Reference
└───controllers // "Main directory"
├───session // "Controller name"
│ ├───add
│ │ index.js // "Route 'session' 'add' index function"
│ │ validate.js // "Validating passed parameters (optional)"
│ │
│ └───delete
│ index.js
│ validate.js
│
└───user
│ policies.js // "Controller global policies, is applied to all actions in controller"
│
├───login
│ index.js
│ policies.js // "Action policies, overwriting controller global policies"
│ validate.js
│
└───logout
index.js
validate.js
Loading such structure will provide you object.
{
session: {
add: [ [Function], [Function] ],
delete: [ [Function], [Function] ]
},
user: {
login: [ [Function], [Function], [Function] ],
logout: [ [Function], [Function], [Function] ]
}
}
API Example
const router = require('v50-router')
// './test/controllers' directory where fails are located
router(resolve('./test/controllers'), {}, (err, config) => {
console.log(err)
console.log(config)
})
API example optional
Optional, load single controller
// './test/controllers' directory where fails are located
// Secondary parameter "controller" options allows to load single controller
router(resolve('./test/controllers'), {controller: 'user'}, (err, config) => {
console.log(err)
console.log(config)
})
Optional, load single action
// './test/controllers' directory where fails are located
// Secondary parameter "controller" options allows to load single controller
// Secondary parameter "action" option allows to load single action
router(resolve('./test/controllers'), {controller: 'user', action: 'login'}, (err, config) => {
console.log(err)
console.log(config)
})
For more examples see tests
Tests
npm test
Contributors
Edgars Mjasnikovs
License
MIT