cari

Rumah  >  Soal Jawab  >  teks badan

Posmen tidak boleh memaparkan butiran individu nod apabila menggunakan parameter

Dalam projek reaksi saya, saya perlu mendapatkan satu butiran halaman butiran menggunakan parameter tetapi respons tidak dihantar kepada posmen. Selepas menghantar permintaan, maklum balas tidak datang kepada posmen

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"));

Penghala

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')
}})

Posmen get--http://localhost:3001/createrecipe/1

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

Anda perlu menyemak butiran item tunggal di halaman butiran dan posmen.

P粉739079318P粉739079318235 hari yang lalu375

membalas semua(1)saya akan balas

  • P粉680487967

    P粉6804879672024-04-03 09:26:04

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

    balas
    0
  • Batalbalas