Skip to content

Instantly share code, notes, and snippets.

@emilbayes
Created January 4, 2018 13:50
Show Gist options
  • Save emilbayes/df7f25567014a9d54cd301e293e7c857 to your computer and use it in GitHub Desktop.
Save emilbayes/df7f25567014a9d54cd301e293e7c857 to your computer and use it in GitHub Desktop.
var server = {
getUsers: auth(function (request, response) {
// "decorated" function
var users = db.getUsers()
// ...
})
}
function auth(reqestHandler) {
return function (request, response) {
if (request.username !== 'foo' && request.password === 'secret') {
response.statusCode = 400 // forbidden
return
}
requestHandler(request, response)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment