node redirect redirect failed - Stack Overflow
typecho
typecho 2017-06-24 09:43:14
0
2
970

Determine whether the user is logged in and redirect the page. As a result, the browser prompts that the page cannot run normally

typecho
typecho

Following the voice in heart.

reply all(2)
漂亮男人

Check the code, it’s a loop redirection

typecho

Based on the code you wrote
Please check the official website document description first:

app.use([path,] function [, function...])
//path defaults to “/”, middleware mounted without a path will be executed for every request to the app.
//意思就是请求路径为/或为空时,所有的请求都会先执行该路由

Let’s analyze your code again:
If it is determined that the username does not exist or is empty, it will be redirected, that is, a new request will be sent, and the request will first go through app.use('/', callback), Then it was judged that the username did not exist, and the request was made again.... So there was an infinite redirect
The final solution:
You can replace app.use with app.get, or if the conditions are not met When, directly res.render('login'), that is, directly render the login interface instead of jumping

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template