Express: Router.get firing twice for the same route on page load

Created on 14 Jul 2018  路  3Comments  路  Source: expressjs/express

In my router

Router.get('/login', IndexController.login);

In my controller

exports.login = (req,res,next)=>{
console.log('login get');
res.render('main/login',{pageTitle: 'Login'});

};

The console logs login get twice, meaning that this is called twice. If I remove the render call then it is logged only once. I have been trying to debug for several days now but still cant seem to figure this one out. When using a curl request from another terminal the log is seen only once as well, but using chrome/firefox/IE yields the double or sometimes triple log call. I don't see this behaviour with POST calls however. -EJS -EXPRESS -Node

UPDATE In chrome dev tools, after inspecting the network tab, I only see 1 GET request being made for the page.

question

Most helpful comment

Ok Following your advice @wesleytodd I discovered it was an extra call from an img tag on the page, it seems it was making an extra url call.

All 3 comments

My guess is that your view is making a request you were not planning on. Maybe a favicon or an xhr reuest? I would check your browser network tab.

Thanks for the reply @wesleytodd I checked the network tab as you suggested, I notice an initial request followed at some point later by another request to the same URL not sure why that one is being called, but an "img" requested it. Are you familiar with how to resolve this? or should I just tinker with all the images until i figure it out?

Ok Following your advice @wesleytodd I discovered it was an extra call from an img tag on the page, it seems it was making an extra url call.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

guyisra picture guyisra  路  3Comments

HafidAbnaou picture HafidAbnaou  路  3Comments

ZeddYu picture ZeddYu  路  3Comments

cuni0716 picture cuni0716  路  3Comments

haider0324 picture haider0324  路  3Comments