Skip to content

Instantly share code, notes, and snippets.

@themasch
Created November 14, 2012 01:57
Show Gist options
  • Select an option

  • Save themasch/4069769 to your computer and use it in GitHub Desktop.

Select an option

Save themasch/4069769 to your computer and use it in GitHub Desktop.
idea: javascript annotation powered controllers (for express)
Controller.create('Test', {
/**
* @Route('/')
*/
indexAction: function(req, res)
{
},
/**
* @Route('/edit', { method: POST })
* @Route('/edit', POST)
*/
editMethod: function(req, res)
{
},
/**
* @Route('/hello/:name')
* @Route('/hello/')
* @FilterBefore('Test.loadStuff')
*/
hello: function(req, res)
{
if(req.param('name')) {
res.end('Hello ' + req.param('name'))
} else {
res.end('Hello ' + res.locals.world +'!')
}
},
/**
* @ProvidesFilter('loadStuff')
*/
loadStuffINeed: function(req, res, next)
{
res.locals.world = "World"
next()
}
});
/**
* there should be a way to create new annotations like:
* @LoadSomeStuffINeed
* @RequirePermission('edit_this_stuff')
*
* These Annotations should be provided by other modules.
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment