Open
Description
I'd like to implement middleware that returns formatted json in the response when pretty_ouput
is present on the query. I attempted this with the following code:
// This code does not work as expected.
app.use(function(req, res, next) {
// Querystring `pretty_output` should prettify json output.
if (req.query['pretty_ouput']) {
app.set('json spaces', 2); // I'd like to set this only for this one request.
}
next();
});
However, subsequent requests without the pretty_ouput
querystring are also formatted.
Is there a way to set the setting json spaces
for only one request? Ideally I could call res.set('json spaces', 2)
that would set this option for only this one response. I'd think this would be generically useful for any Express option.