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?
CodePudding user response:
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.