Postman 使用參數時無法顯示節點的個別詳細信息
P粉739079318
P粉739079318 2024-04-02 19:59:35
0
1
286

在我的反應項目中,我需要使用參數將單一詳細資訊取得到詳細資訊頁面,但回應未傳送到郵差。發送請求後,回應未傳入郵遞員

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

#
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!