I am encountering an issue with my code and I have tried looking for solutions in other similar questions without any success. Is there anyone who can assist me?
Here is the content of my route.js file:
import dbConnect from "@/lib/dbConnect";
import User from "@/models/User";
import { NextResponse, NextRequest } from "next/server";
import type { NextApiResponse, NextApiRequest } from "next";
export async function POST(req: NextApiRequest) {
await dbConnect();
let data = await req.body;
console.log(data); //HERE ReadableStream { locked: false, state: 'readable', supportsBYOB: false } HERE
try {
const user = await new User(data);
await user.save();
return NextResponse.json({ user }, { status: 201 });
} catch (error) {
console.log("here 3");
if (error instanceof Error) {
return NextResponse.json(
{ error: error.message || "unknown error" },
{ status: 500 }
);
} else {
return NextResponse.json(
{ error: "unknown error" },
{ status: 500 }
);
}
}
}
Below is the request I made:
try {
const res = await fetch("http://localhost:3000/api/register", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(data),
});
const dataRes = await res.json();
console.log("dataRes" + dataRes);
} catch (error) {
console.log(error);
}