express-stormpath
express-stormpath copied to clipboard
Auto-expand application customData
In my latest blog post about Stormpath on HyperDev, I had to write sample code that looks like this:
app.get('/global-counter', function(req, res) {
req.app.get('stormpathApplication').getCustomData(function(err, customData) {
if(!customData) {
return res.status(500).send("Internal Server Error")
}
if(typeof customData.visitCount != "number") {
customData.visitCount = 1
}
res.send("People have visited this page " + customData.visitCount + " times!")
customData.visitCount = customData.visitCount + 1
customData.save()
})
})
I think it makes sense for the {expand: "customData"} config option to also add customData to stormpathApplication, so I only have to do:
req.app.get('stormpathApplication').customData