====
// use case 1
path: '/admin',
call: 'admin.help'
ac.url.make('admin.help') => /admin
ac.url.find('/admin')
app.get('/admin', mojito.dispatch('admin.help'));
// use case 2 - same as #1
path: '/admin/help',
call: 'admin.help'
ac.url.make('admin.help') => /admin/help
ac.url.find('/admin/help')
app.get('/admin/help', mojito.dispatch('admin.help'));
// use case 3
path: '/admin/:mojitAction'
call: 'admin.index'
ac.url.make('admin.index', { mojitAction: 'help' }, ..) => /admin/help
ac.url.find('/admin/foo'); // ???
// this is a valid use case
app.get('/admin/:mojitAction', mojito.dispatch('admin.index'));
// use case 4
path: '/admin/:mojitAction'
call: 'admin.{mojitAction}'
ac.url.make('admin.foo', ...) => /admin.foo
// in expressjs app.js
app.get('/admin/:mojitAction', function (req, res, next) {
var mojitAction = req.params.mojitAction;
return mojito.dispatch('admin.' + mojitAction)(req, res, next);
});
// expressjs routes definitions are configured at startup time
// by the time the first request is served, those definitions cannot
// be changed, in contrast to previous version of mojito where
// route lookup and resolution was being down at runtime.
// THIS IS NOT SUPPORTED IN #next
//
// Recommended Work Around:
// TODO:
// #current: ac.url.make('admin.foo', {}, 'GET', {})
// #next :
// use case 5
path: '/:type/:action'
call: '{type}.{action}'
ac.url.make('bing.o', …) => /bing/o
ac.url.make('bing.index') => /bing/help
// This is similar to use case #4
app.get('/:type/:action', function (req, res, next) {
var type = req.params.type,
action = req.params.action;
return mojito.dispatch(type + '.' + action)(req, res, next);
});
mojito.dispatcher
at startup time does not have access to the path
. How to match the dispatcher with the route object ?