0.0.1 • Published 7 years ago

v50-load-controller v0.0.1

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

v50-load-controller (ES6, ALFA)

v50-load-controller provides easy to use REST API (Could be you used for anything) configuration loading. No configuration files. Create your API construction in natural human why, just create files and add them in proper project directory. v50-load-controller will load policies, validation, and index function to execute.

File structure example

└───controllers
    ├───session
    │   ├───add
    │   └───delete
    └───user
        ├───login
        └───logout

Installation

npm -i --save v50-load-controller

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] ] } }

Example

const v50LoadController = require('v50-load-controller')

v50LoadController(resolve('./test/controllers'), {}, (err, config) => {
	console.log(err)
	console.log(config)
})

Optional

Optional, load single controller

v50LoadController(resolve('./test/controllers'), {controller: 'user'}, (err, config) => {
	console.log(err)
	console.log(config)
})

Optional, load single action

v50LoadController(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