vercel 部署的 next13 的应用,使用 app 路由、api route, post 导致 get 返回数据缺失一部分?

查看 20|回复 0
作者:linzhe141   
GET 和 POST 同时写入 api/nav/route.ts 文件中。本地开发环境正常。但是通过 vercel 部署后,GET 请求返回数据缺失了一部分。如果把 POST 函数注释掉,GET 请求返回正常结果?

app/api/nav/route.ts
export async function GET(request: Request) {
  const test = []
  for (const name of await fs.readdir(
    path.resolve(process.cwd(), 'app/blog/data_structure/tree')
  )) {
    test.push(name)
  }
  const result = {
    code: 200,
    test: test,
  }
  return NextResponse.json(result)
}
export async function POST(request: Request) {
  return NextResponse.json({ data: true })
}
vercel 环境 没有注释掉 POST 的 nav 请求,少了个 page.tsx 数据
{
    "code": 200,
    "test": [
        "readme.mdx"
    ]
}
vercel 环境 注释掉 POST 的 nav 请求,就正常了
{
    "code": 200,
    "test": [
        "page.tsx",
        "readme.mdx"
    ]
}
最小复现,https://github.com/linzhe141/minimal-nextjs-isssue
您需要登录后才可以回帖 登录 | 立即注册

返回顶部