I've got my routes set up like below
When i navigate to 'http://localhost/' i get an error saying 'localhost redirected you too many times' and the URL of the page (showing in the URL bar of the browser) is http://localhost/!/dashboard - so it does look like it is being redirected, but i cannot see why it's getting stuck in an infinite loop
// Public Routes
app.use('/', function(req,res){
res.redirect('/!/dashboard');
});
app.use('/login', routes.login);
app.use('/!/dashboard', isLoggedIn, routes.dashboard);
// Check If Logged In
function isLoggedIn(req,res,next){
if (req.isAuthenticated()){
return next();
} else {
res.redirect('/login');
}
};
The ERR_TOO_MANY_REDIRECTS error occurs when the browser is redirected to a different URL, which in turn points back to the original one, creating a redirection loop.
This feature, unfortunately, can cause interruptions when a site uses an authentication service such as Google, which can lead to an error known as “Too many redirects”. This error occurs as Safari's new ITP is blocking authentication checks between Google and services such as Securly.
You shouldn't use app.use('/', ...)
, because that will match any URL starting with a /
.
Instead, use app.all
:
app.all('/', function(req,res){
res.redirect('/!/dashboard');
});
app.use('/login', routes.login);
app.use('/!/dashboard', isLoggedIn, routes.dashboard);
Classical error would stand in your configuration of Apache/Nginx. In your code, you seem to be using port 80, which I believe you are not using and therefore you would be proxying your requests through Apache or Nginx.
(can't comment so even though this is a poor answer, I will update it accordingly on further comments)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With