Created
August 21, 2014 14:26
-
-
Save molekilla/0feda8cecd14e6f20830 to your computer and use it in GitHub Desktop.
hapi-server-config
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
server.pack.register(require('hapi-auth-bearer-token'), function(err) { | |
server.auth.strategy('token', 'bearer-access-token', { | |
validateFunc: function(token, callback) { | |
// read from db or some place | |
var matched = false; | |
var tokenResult = { token: token }; | |
var err = null; | |
if (token === 'a1b2c3') { | |
matched = true; | |
} else { | |
tokenResult = null; | |
err = { error: 'Unauthorized' }; | |
} | |
return callback(err, matched, tokenResult); | |
} | |
}); | |
// health check | |
server.route({ | |
method: 'GET', | |
path: '/api/health', | |
config: { | |
handler: function(req, reply) { | |
reply('OK'); | |
} | |
} | |
}); | |
server.pack.register(controllers, | |
{ | |
route: { | |
prefix: '/api' | |
} | |
}, function() { | |
if (!module.parent) { | |
server.start(function () { | |
console.log('Server started at port ' + server.info.port); | |
}); | |
} | |
}); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment