0

I'm getting into the backend with Node and express , I wanted to create a middleware that show on the console that the route was not found if you try to do a request to a route that does not exist , so I did this way

server.get('/' , (req,res) => {
    res.render('index.html')
})

server.use((req,res,next) => {
    console.log('NOT FOUND')
})

If i'm not wrong , this middleware should just execute if I do the request to a route that is not / since it is the only that exist , and when I try in postman it have exactly the behavior that it should , but when I try on the browser it execute the middleware even if the request is to / and my view is render and sometimes it even execute it two times and it show NOT FOUND two times on the console

I don't know why Postman and the Browser are doing different things , Am I doing something wrong?

Thanks for the help

ManuC12
  • 33
  • 5

2 Answers2

1

There is not a lot of information here, but my best guess would be that maybe index.html references som other resources (js,css, favicon, ++) that it tries to load, but it does not find. Whereas postman does not try to load these resources?

Update: as per OPs comment, to "disable" favicons, have a look at this post: How to prevent favicon.ico requests?

Andreas
  • 341
  • 2
  • 9
0

If I do a console log on the middleware of req,originalUrl it shows /favicon.ico , but why does it try to load a favicon if I dont have any reference to it in my html ? , my html just have the basic structure and no more , how could I solve this ? Anyway thanks for the answer because I feel more close to solve the problem than before for sure

ManuC12
  • 33
  • 5