2021年1月22日星期五

How to ignore specific files to be loaded when I use route parameters in Express

When I make a GET request with route parameters in express with mongoose like the following code, I sometimes see that the browser tries to load some unexpected files such as favicon.ico, robots.txt, humans.txt, sitemap.xml, ads.txt, etc., and 404 error shows up in the browser console.

app.get("/:userId", ...);  

By refering to this Q&A, I figured out that if I don't use the route parameters right after the root route like the following code, it doesn't happen.

app.get("/user/:userId", ...);  

In the same Q&A, however, there seem to be another way that uses req.url to ignore those unexpected files to be loaded, but it isn't explained in detail. How do you do that?

https://stackoverflow.com/questions/65854950/how-to-ignore-specific-files-to-be-loaded-when-i-use-route-parameters-in-express January 23, 2021 at 09:45AM

没有评论:

发表评论