So I have a landing page ('/'). On this page is a login form for a username and password with a submit button. I have the app.get that loads the page and an app.post to receive the parameters of the form. However, my intention is to have an app.post('/login', function (req, res){ //logic}); There is no /login route or page to load, this would simply house the logic for the login itself (validation of the username, etc.) Is there an easy way to get the post from '/' to redirect into the post for /login without it trying to load the /login page, which does not exist?
相关问题
- npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fs
- HTML form is not sending $_POST values
- Axios OPTIONS instead of POST Request. Express Res
- POST Base64 encoded data in PHP
- google-drive can't get push notifications
相关文章
- C#中 public virtual string Category { get; }这么写会报错:
- 请大神帮忙 post向https接口发送数据 部署到服务器为什么运行一会后就会报空指针
- node连接远程oracle报错
- WCF发布Windows服务 POST方式报错 GET方式没有问题 应该怎么解决?
- 用 $.ajax POST 请求数据报错
- 设备发送一个http post请求,接收不到
- How can make folder with Firebase Cloud Functions
- @angular-cli install fails with deprecated request
I'm not sure if I understand your question correctly. As I understand you want your POST request to
/
get redirected to POST requests to/login
which can be tricky.Usually you do redirects by sending either 301 Moved Permanently or 302 Found HTTP status code. Both of them usually work in practice as if it was 303 See Other and a GET request is made. See List of HTTP status codes on Wikipedia:
There is a 307 Temporary Redirect (since HTTP/1.1) created to address this issue that is not allowed to change the HTTP method - so a redirect from POST should still be POST - see Wikipedia:
As far as I know browsers should warn users before following such redirects. I don't know how that works in practice. I wouldn't rely on that since it can be annoying to users at best or even not work at all.
My suggestion would be to either change this:
to this:
or something like this, using regular expressions:
That way instead of a redirect the same handler will be used for both of those routes. It would be both faster and more robust because that way you don't rely on the redirect working as you want - there is no redirect at all.