First, let's understand what res.redirect
does:
res.redirect([status,] path)
Redirects to the URL derived from the specified path, with specified HTTP status code status. If you don’t specify status, the status code defaults to “302 “Found”.
If we look at the HTTP 1.1 spec for a 302 response, we see
Note: For historical reasons, a user agent MAY change the request
method from POST to GET for the subsequent request. If this
behavior is undesired, the 307 (Temporary Redirect) status code
can be used instead.
A 307 request will preserve the HTTP verb in all cases, but that's not want you want. You want the verb to change to GET. In that case, you want a 303:
303 See Other
The 303 (See Other) status code indicates that the server is
redirecting the user agent to a different resource, as indicated by a
URI in the Location header field, which is intended to provide an
indirect response to the original request. A user agent can perform
a retrieval request targeting that URI (a GET or HEAD request if
using HTTP), which might also be redirected, and present the eventual
result as an answer to the original request.
A 303 response will prompt the client (provided it understands HTTP 1.1) to perform a GET request on the specified resource. So, simply provide a 303 status code in your redirects:
res.redirect(303, '/test')