App.get("*") is responding to every incoming URI - how do I stop this?

  app.get("*", (req, res) => {
    var asdf = req.url;
    res.send(`404 Error: Requested path ${req.url} does not exist`)
    }) 

So this is my code block, which is supposed to show a custom 404 page ONLY if the requested url wasn’t found. However, now it fires on literally every input, path, whatever. How can I fix this? It’s placed pretty close to the beginning of the top of my app.

It’s placed pretty close to the beginning of the top of my app.

That’s your problem. You need to place it after all your other routes.

5 Likes

Yep, you need it right smack at the bottom of everything

2 Likes