Postman 使用参数时无法显示节点的个别详细信息
P粉739079318
P粉739079318 2024-04-02 19:59:35
0
1
393

在我的反应项目中,我需要使用参数将单个详细信息获取到详细信息页面,但响应未发送到邮递员。发送请求后,响应未传入邮递员

index.js
import express from "express";
import cors from "cors";
import mongoose from "mongoose";
import { userRouter } from "./routes/users.js"
import { recipesRouter } from "./routes/recipes.js"
const app = express();
app.use(express.json());

app.use(cors());

 app.use("/auth", userRouter);
 app.use("/recipes", recipesRouter);

mongoose.connect(
"xxxxxxxxxxxxxxxxxxxxxx"
);
app.listen(3001, () => console.log("SERVER STARTED"));

路由器

import express from "express";
import mongoose from "mongoose";
import { RecipeModel } from "../models/Recipes.js"
import { UserModel } from "../models/User.js";
const router = express.Router();
router.get("/createrecipe/:id",  async (req, res) =>{
let result =await RecipeModel.findOne({id:req.params.id});
if(result){
    res.send(result)
}else{
    res.send('no recipe')
}})

邮递员 get--http://localhost:3001/createrecipe/1

<body>
    <pre>Cannot GET /createrecipe/1</pre>
</body>

需要在详情页和邮递员中查看单件详情。

P粉739079318
P粉739079318

全部回复(1)
P粉680487967

app.use("/recipes",recipesRouter)中,您正在为recipesRouter中的所有路由添加/recipes前缀,但您正在调用http://localhost:3001/createrecipe/1 而不是 http://localhost:3001/recipes/createrecipe/1

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板