express icon indicating copy to clipboard operation
express copied to clipboard

Docs don't mention that 'status' is a special parameter for res.render

Open sebm opened this issue 15 years ago • 3 comments

I had been writing code like:

app.get('/', function(req, res){
  res.render('index', {
    status: 'Hey, this is my status!'
  });
});

completely oblivious to the fact that, thanks to this line, res.render puts the contents of 'status' into the HTTP header when it's set, eg the above produces "HTTP/1.1 200 this is my status! unknown" instead of the legal "HTTP/1.1 200 OK'. As an example of the havoc this wreaks, it turns out that Heroku suppresses your app's outgoing traffic (without explicitly stating why) if it's not sending out legal 200 OKs.

Could you possibly update the docs to warn against naming a view parameter 'status'? Thanks!

sebm avatar Jul 07 '11 03:07 sebm

wish js had macros we could also check for a non-number in development and warn based on that

tj avatar Jul 07 '11 03:07 tj

Alternatively, do you think it might be worth rewriting view.js#L359 so that it looks for eg options.HTTPStatus instead of options.status? I understand that wouldn't be backwards-compatible with preexisting templates, but there's a case to be made for it - I imagine 'status' would be a very common variable name to put in a template, whereas HTTPStatus or whatever is very explicitly referring to the HTTP status.

sebm avatar Jul 07 '11 14:07 sebm

Here's a pull request if you decide the above suggestion makes sense: #741

sebm avatar Jul 07 '11 15:07 sebm