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
Check the code, it’s a loop redirection
Based on the code you wrote
Please check the official website document description first:
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 redirectThe final solution:
You can replace
app.use
withapp.get
, or if the conditions are not met When, directlyres.render('login')
, that is, directly render the login interface instead of jumping