2.1.1 • Published 3 years ago
dirigent v2.1.1
Dirigent
Simple router for expressjs with named routes and formatUrl
helper function to genrate urls.
Bro, why?
All modules I tried needs app to be passed or have outdated path-to-regexp module.
Install
$ npm install dirigent
Usage
routes.js
const Dirigent = require('dirigent')
// controllers
const homeController = require('./controllers/home');
const searchController = require('./controllers/search');
const router = new Dirigent();
router.get('home', '/', homeController.index);
router.get('search', '/cars{/make-:make}?{/model-:model}?{/location-:location}?', searchController.index);
module.exports = router;
app.js
app.use(router.middleware.bind(router));
app.formatUrl = router.formatUrl.bind(router);
API
Supported methods
checkout
, copy
, delete
, get
, head
, lock
, merge
, mkactivity
, mkcol
, move
, m-search
, notify
, options
, patch
, post
, purge
, put
, report
, search
, subscribe
, trace
, unlock
, unsubscribe
method
router.get('details', '/details/:id', (req, res, next) => {
console.log(req.params.id)
})
middleware(req, res, next)
Pass it to app.use
.
formatUrl(route, params)
app.formatUrl('search', { make: 'Honda' })