Created
August 11, 2017 19:30
-
-
Save clarkio/cdd00683870329464a27847348ae2c8e to your computer and use it in GitHub Desktop.
Restify middleware next() blog post code snippets
This file contains 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
server.get('/secure/route', | |
// My short-circuiting middleware "module" | |
function checkAuthorization (req, res, next) { | |
res.send(401, 'Unauthorized'); | |
return next(false); | |
}, | |
// My route implementation | |
function routeAction (req, res, next) { | |
res.send(200, { data: 'secure data' }); | |
return next(); | |
} | |
); |
This file contains 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
server.get('/secure/route', | |
// My short-circuiting middleware "module" | |
function checkAuthorization (req, res, next) { | |
res.send(401, 'Unauthorized'); | |
return next(); | |
}, | |
// My route implementation | |
function routeAction (req, res, next) { | |
res.send(200, { data: 'secure data' }); | |
return next(); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment