res.redirect: Code examples should show default HTTP status code 302 instead of 301
Description
Was migrating from Express 4 to 5 recently. Followed the docs and replaced res.redirect(url) with res.redirect(301, url) as per the code examples in the migration guide.
My bad on not checking that 301 is a permanent redirect. Only found out later when I could not log out from my application.
Read the fine text and saw that the status code, if not specified, defaults to 302, which is a temporary redirect. Updated my application code but had to clear browser cache.
Expectations
Code examples for res.direct(status, url) should use the default status code, which is 302.
- https://expressjs.com/en/5x/api.html#res.redirect
- https://expressjs.com/en/guide/migrating-5.html#res.redirect
- https://expressjs.com/en/4x/api.html#res.redirect
Code examples should use default values to prevent confusion, as developers would likely jump straight to them instead of reading through paragraphs of text, especially when the method parameters are few and seemingly straightforward.
Opened expressjs/express#7236.
The migration guide says to replace res.redirect(url, 301) with res.redirect(301, url). Nowhere does it say that res.redirect(url) is not supported. It uses 301, because it is the status that developers are most likely to use if they don't want the default 302.
I think it would be more obvious, if the signatures in migration guide showed that status is optional.