express middleware functions invoked twice when request is made from browser

后端 未结 2 1181
说谎
说谎 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:26

    The usual reasons you see multiple requests when a page loads from a browser are one of two things:

    1. The browser automatically requesting the favicon.ico file.
    2. The browser attempting to load some resource from the HTML file (script file, image, CSS file, etc..)

    You can see exactly what each request is for by adding:

    console.log(req.url);
    

    to your middleware.

提交回复
热议问题