I want to turn every res.render
to res.json
for the whole application. The reason I'm doing so is to avoid bad code as only in development environment, I would like to return JSON rather than HTML.
I found this question and following the solution I thought it would work with:
const renderToJson = function(req, res, next) {
res.render = function(view, options, callback) {
res.status(200).json(res, view, options, callback);
};
};
app.use(renderToJson);
Or
const renderToJson = function(req, res, next) {
const _render = res.status(200).json;
res.render = function(view, options, callback) {
_render.call(res, view, options, callback);
};
};
app.use(renderToJson);
But unfortunately it didn't. I continue to receive HTML with no errors.