ethanresnick / json-api

Turn your node app into a JSON API server (http://jsonapi.org/)
GNU Lesser General Public License v3.0
268 stars 41 forks source link

Framework's request and response on beforeSave #173

Open cuongtavan opened 6 years ago

cuongtavan commented 6 years ago

@ethanresnick While doing work with latest version 3.0.0-rc.6.0.1, I can't get data/property that I make change on Express middlewares before passing to the library For example: with express session, req.session now is undefined it works fine before (I tested with 3.0.0-beta.24)

beforeSave: function(resource, req, res, superFn) {
//can't get req.session here
}
ethanresnick commented 6 years ago

Ah, yeah. As documented here, the signature for beforeSave and beforeRender changed in 3.0.0-rc.3. That link explains the new signature. Basically, instead of req.session, you'll use extras.serverReq.session

ethanresnick commented 6 years ago

Note: more generally, there have been a few breaking changes in the RCs, so I'd definitely recommend reviewing the changelog before upgrading if you aren't already. I try to document breaking changes pretty thoroughly there.

cuongtavan commented 6 years ago

Thank you so much! I think lot of developers will firstly look at the example on README.md - which haven't been updated with latest change. That's a big cause to the issue and would be great if it's always be up to date

ethanresnick commented 6 years ago

I think lot of developers will firstly look at the example on README.md - which haven't been updated with latest change.

Ahh, thank you for pointing this out. I didn't realize it hadn't been updated. Will reopen this issue as a reminder to myself to update that. A PR would also be welcome, if you feel inspired.