简体   繁体   中英

Express .use() callback gets called multiple times when using express.static()

I'm trying to authenticate user and once authenticated I want to create a new user in my own database with the data provided by authentication server.

The problem I am facing is that this createNewAccount() gets called 3 times. I don't exactly know why but once I removed the express.static('app/web') call this no longer happens. Still I need that call to serve static content, can someone tell me what I am doing wrong?

expressApp.use('/console',requiresAuth(),express.static('app/web'), (req,res)=>{
    createNewAccount(req.oidc.user.email);

});

It might be additional requests to static files like favicon.ico, manifest.json etc.

so callback fires on each of them :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM