Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is there a limit to the number of routes?

Here’s my issue with Express.Router. I need these 4 routes to work at the same endpoint "/pets/…":

petRouter.get("/", petController.getAll);
petRouter.get("/:id", petController.getPetById);
petRouter.get("/mypets", verifyToken, petController.getAllUserAdoptions);
petRouter.get("/myadoptions", verifyToken, petController.getAllUserAdoptions);

But whats going on is that I can’t use the second one ("/:id") together with the rest. It keeps breaking the server and it gives me this error:

    return new sequelizeErrors.DatabaseError(err);
                   ^
    DatabaseError [SequelizeDatabaseError]: invalid input syntax for type integer: "mypets" 
     ...

And when I use them independently all of them work just fine. Is there any kind of limitation that I’m unaware of?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The request GET /pets/mypets matches both the second and the third route. In the second route, this leads to req.params.id = "mypets", but petController.getPetById probably assumes that this is an integer. Hence the error that you observed.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading