refactor: remove setting req.body to undefined
Reasoning: the various parsers should not modify the request object until it is clear it should be applied. Setting a property, even to undefined, may affect assumptions elsewhere. For example, 'req' in body would be truthy even if the rest of the middleware was not applied.
It can be removed entirely since all tests are still passing without it. However, I recognize that some third-party consumers may still need it to be set.
In either case, the current version is not compatible with, for example, tRPC v11 when using FormData. So without this change, the workaround is to add a condition to avoid applying the middleware at all. Example:
const json = express.json();
app.use((req, res, next) => {
if (req.url.includes('trpc')) return next();
return json(req, res, next);
});
Hey @UlisesGascon what do you think?
I'm in favor of removing it completely,
I'm neutral on this, i'd need to do a bit more research to see if this validation is really necessary.
Updated: rebased to resolve conflicts and changed it to remove the lines instead.