new Router(name)
Router class
Parameters:
Name | Type | Description |
---|---|---|
name | string | Name of the Router |
- Since
- 1.0.0
- Copyright
- MIT
Example
const {Router} = require('@neobeach/core');
const IndexController = require('./IndexController');
const router = new Router('Api');
router.add('/api', IndexController);
module.exports = router;
Members
name :string
Router name used for internal logs
Type:
- string
- Since
- 1.0.0
- Copyright
- MIT
routes :array.<object>
Array of routes which to implement within Express
Type:
- array.<object>
- Since
- 1.0.0
- Copyright
- MIT
Methods
add(path, controller, middlewaresopt)
Binds a controller to a path within an Express Router
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
path | string | A path to bind the controller to | |
controller | * | A Controller class reference | |
middlewares | array.<function(*, *, *)> | <optional> | An array of middleware functions |
- Since
- 1.0.0
- Copyright
- MIT
Example
const {Router} = require('@neobeach/core');
const IndexController = require('./IndexController');
const router = new Router('Api');
router.add('/api', IndexController);
module.exports = router;