Express js prevent GET /favicon.ico

前端 未结 4 1570
忘掉有多难
忘掉有多难 2020-12-07 23:13

In every request, my server is receiving GET request to /favicon.ico, even when it\'s REST api that not include html file. Why is this happening and how can I prevent this r

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-07 23:31

    my preferred method is middleware

    put this somewhere:

    function ignoreFavicon(req, res, next) {
      if (req.originalUrl.includes('favicon.ico')) {
        res.status(204).end()
      }
      next();
    }
    

    then:

    app.use(ignoreFavicon);
    

提交回复
热议问题