Created
July 7, 2016 10:04
-
-
Save just-boris/4d212d3165cfab4526f517e17f45bceb to your computer and use it in GitHub Desktop.
configure express routes through decorators
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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