express-stormpath icon indicating copy to clipboard operation
express-stormpath copied to clipboard

Auto-expand application customData

Open edjiang opened this issue 9 years ago • 0 comments

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

edjiang avatar Jun 03 '16 17:06 edjiang