我想不通。为什么是我的请求:
localhost:3000/api/customers/search?q=glenn
转到:
// Retrieve a single Customer with customerId
router.get("/:customerId", customers.findOne);
它应该什么时候送到这里???
// Search for a customer.
router.get("/search/:q", customers.search)
客户路线.js
module.exports = app => {
const customers = require("../controllers/customer.controller");
const router = require("express").Router();
// Create a new Customer
router.post("/", customers.create);
// Retrieve all Customers
router.get("/", customers.findAll);
// Search for a customer.
router.get("/search/:q", customers.search)
// Retrieve a single Customer with customerId
router.get("/:customerId", customers.findOne);
// Update a Customer with customerId
router.put("/:customerId", customers.update);
// Delete a Customer with customerId
router.delete("/:customerId", customers.delete);
// Create a new Customer
router.delete("/", customers.deleteAll);
app.use("/api/customers", router)
};
Morgan+Sequelize日志:
执行(默认(:选择
id
、name
、active
,将customers
中的createdAt
、updatedAt
作为customer
,其中customer
。id
="搜索";:1-[2020年4月25日0:16:41:06+0000]"获取/api/客户/搜索?q=glenn HTTP/1.1"200 0"-"PostmanRuntime/7.24.1">
您的请求与路由器想要的不匹配,请将您的请求从localhost:3000/api/customers/search?q=glenn
更改为localhost:3000/api/customers/search/glenn
或
将router.get("/search/:q", customers.search)
更改为router.get("/search", customers.search)
您需要处理另一条路由,搜索时不使用"/:r"。
/search/:q
仅适用于类似的查询
/search/test
/search/something
不
/search?q=something
更新:
// Search for a customer.
router.get("/search/:q", customers.search)
// Add this
// Search for a for query.
router.get("/search", customers.search)