arb / celebrate

A joi validation middleware for Express.
MIT License
1.33k stars 66 forks source link

node 16 Object.defineProperty compatibility #235

Closed slimee closed 2 years ago

slimee commented 2 years ago

Is using two times celebrate for the same route discouraged?

Maybe that will interest you:

Celebrate can't be used twice on the same endpoint when using node 16 instead of node 14. It's because of `Object.defineProperty(request, 'headers', ...) that is made, the property is made read-only the first time, so it fails the second time. Why not just do "request['headers'] = value" ?

We are currently changing our code to have only one celebrate call.

Regards

arb commented 2 years ago

I would suggest only using one celebrate call per route and put all of the validation rules into that single call. I'm actually not sure the use case where you would want to call it multiple times 🤔

request['headers'] = value fails on newer version of Express. If you're interested in the full story, check out https://github.com/arb/celebrate/issues/42. It actually was this way prior to Express 5.

I'm not a fan of that line you're referring to above, but it was far easier than trying to get express to change their code/APIs.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.