Next.js 中 JSON 输入意外结束

Cho*_*wka 6 javascript json reactjs next.js

我正在从中获取数据/api/notes/1并接收以下内容:

{
"id":1,
"author":1,
"title":"Pierwsza notka",
"excerpt":"Taka tam notka, bla bla bla",
"body":"Pirwsza notka elo",
"private":1,
"created_at":"2021-04-07T12:59:59.000Z",
"updated_at":"2021-04-07T12:59:59.000Z"
}
Run Code Online (Sandbox Code Playgroud)

这很好,但是当我将它传递到 Next 时getStaticProps

export async function getStaticProps({ params }) {
  const res = await fetch(`${config.apiURL}/notes/${params.id}`);
  const post = await res.json();

  return { props: { post } };
}
Run Code Online (Sandbox Code Playgroud)

它返回一个错误:

FetchError: invalid json response body at http://localhost:3000/api/notes/1 reason: Unexpected end of JSON input
Run Code Online (Sandbox Code Playgroud)

这里发生了什么?

Cho*_*wka 4

问题是我的错。提取返回 401 Unauthorized,没有正文。