我有一个 Next.js 应用程序,它具有连接到 MongoDB 和 Prisma 的功能 API。在开发过程中,一切都很顺利。但是部署应用后,API页面返回404错误。它是用vercel部署的。
这里是app/api/blog/route.ts
import {db} from "@/lib/db";
import { NextResponse } from "next/server";
export async function GET(){
try{
const todos=await db.post.findMany({
orderBy:{
date:"desc",
}
});
return NextResponse.json(todos,{status:200})
}catch(error){
console.log("[GET TODO]",error)
return new NextResponse("Internal Server Error",{status:500})
}
}
这里是app/api/blog/[id]/route.ts
import {db} from "@/lib/db";
import { NextResponse } from "next/server";
export const GET = async (request:any,{params}:any)=>{
try{
const {id}=params;
const post=await db.post.findUnique({
where:{
id
}
});
if(!post){
return NextResponse.json(
{message:"Post not found",error: "Post not found"},
{status:404}
)
}
return NextResponse.json(post)
}catch(err){
return NextResponse.json({message:"GET Error",err},{status:500})
}
}
这是package.json
{
“名称”:“投资组合”, “版本”:“0.1.0”, “私人”:真实, “脚本”:{ “dev”:“下一个开发者”, “构建”:“下一个构建”, "start": "下次开始", "lint": "下一个 lint", “postinstall”:“prisma 生成” }, “依赖项”:{ "@material-tailwind/react": "^2.1.6", "@motionone/utils": "^10.16.3", "@prisma/client": "^5.7.1", "@radix-ui/react-dropdown-menu": "^2.0.6", "@radix-ui/react-slot": "^1.0.2", "@tsarticles/engine": "^3.3.0", "@tsarticles/react": "^3.0.0", "@tsarticles/slim": "^3.3.0", "@vercel/analytics": "^1.2.2", "类方差权威": "^0.7.0", "clsx": "^2.1.0", "dotenv": "^16.3.1", "framer-motion": "^10.18.0", "lucide-react": "^0.294.0", "mongodb": "^6.3.0", “下一个”:“14.0.3”, "下一个主题": "^0.2.1", “反应”:“^18”, "react-awesome-reveal": "^4.2.8", "react-dom": "^18", "react-hot-toast": "^2.4.1", "反应类型动画": "^3.2.0", "重新发送": "^3.2.0", "顺风合并": "^2.2.1", "tailwindcss-animate": "^1.0.7", "tailwindcss-filters": "^3.0.0", “打字机效果”:“^2.21.0” }, “开发依赖项”:{ "@types/node": "^20", “@types/react”:“^18”, "@types/react-dom": "^18", “自动前缀”:“^10.0.1”, “eslint”:“^8”, “eslint-config-next”:“14.0.3”, "postcss": "^8", "棱镜": "^5.7.1", "tailwindcss": "^3.3.0", “打字稿”:“^5” } }
我尝试检查 envs 并将 mongodb atlas 与 vercel 集成。似乎没有任何效果。 您可以在[此处]检查已部署的站点(https://yasith.vercel.app/) 请帮助..,这阻止了我使用下一个 js 进入全栈。