Skip to content

Instantly share code, notes, and snippets.

@just-boris
Created July 7, 2016 10:04
Show Gist options
  • Save just-boris/4d212d3165cfab4526f517e17f45bceb to your computer and use it in GitHub Desktop.
Save just-boris/4d212d3165cfab4526f517e17f45bceb to your computer and use it in GitHub Desktop.
configure express routes through decorators
function factory(app) {
return ({url, method = 'get'}) => (target, key, descriptor) => {
app[method](url, target[key]);
}
}
const Path = factory(app);
class Controller {
@Path({url: '/ping'})
ping(req, res) {
res.send('Ping!')
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment