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

240 天前
 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

378 次点击
所在节点    问与答
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/979439

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX