When you do this:
return res.redirect('https://' + req.get('host') + req.url);
Express will return a 302.
However, that code may not be executed, because of caching (as you suspected).
If your browser previously cached the page, then the browser will send a conditional HTTP request, basically telling Express, “send me the page, but only if it’s changed.” If the page has not changed, Express will send a 304 Not Modified
.
Clear your browser’s cache and try again, or make some small modification to the page.
Under the hood, Express uses node-fresh to decide whether to send a 304
response. The logic is fairly simple and can be seen here. One of the factors it checks is the page’s ETag (a hash of the page body). So any small change to the page will force your browser to refresh it. Alternatively, you can set Cache-Control: no-cache
if you want to force the browser to get a fresh copy of the page every time.
You can also disable ETags:
app.disable('etag')
Of course this might lead to more traffic that the conditional requests and 304
responses were designed to reduce.