express middleware functions invoked twice when request is made from browser

后端 未结 2 1172
说谎
说谎 2020-12-12 06:42

Below is my nodejs code

const express = require(\'express\');

const app = express();

app.use(\'/\', (req, res, next) => {
    console.log(\"In intercept         


        
2条回答
  •  粉色の甜心
    2020-12-12 07:09

    Found that it is happening due to /favicon.ico request made by browser. Adding specific handler (shown below) prevented default handler from being called twice

    app.use('/favicon.ico', (req, res, next) => {
        console.log('favicon handler');
        res.sendStatus(200);
    });
    

提交回复
热议问题