[英]ExpressJs: Wrong api endpoint triggered
I have this api request:我有这个 api 请求:
http://localhost:5000/api/courses/get_public_course_data_by_id?course_id=454545
And I have these two ExpressJs routes:我有这两条 ExpressJs 路线:
router.get("/:id", (req, res) => {});
router.get("/get_public_course_data_by_id", (req, res) => {});
For some reason, it's always the first endpoint that gets triggered and not the second.出于某种原因,触发的始终是第一个端点,而不是第二个。
You need to add static route before the dynamic route您需要在动态路由之前添加 static 路由
Like This:像这样:
router.get("/get_public_course_data_by_id", (req, res) => {}); // 1st this
router.get("/:id", (req, res) => {}); // then this
The reason is, node router assuming get_public_course_data_by_id
<-- this as id
and processing the request accordingly and get_public_course_data_by_id
is never executed.原因是,节点路由器假设get_public_course_data_by_id
<-- this 作为id
并相应地处理请求,并且永远不会执行get_public_course_data_by_id
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.