【发布时间】:2022-01-03 19:08:37
【问题描述】:
上下文
我正在使用NextJS v11.1.1-canary.11、React v17.0.2 和Typescript v4.3.5。
我想创建一个基于NextJS Typescript documentation 的简单API 端点,因此我在pages/proxy 文件夹中创建了一个名为login.tsx 的文件,其中包含非常简单的API 代码:
import type { NextApiRequest, NextApiResponse } from 'next'
export default function Login(req: NextApiRequest, res: NextApiResponse) {
res.status(200).json({ name: 'John Doe' })
}
我的问题
当我尝试调用该 API 端点时,发生错误:
TypeError: res.status is not a function
at Login (C:\wamp64\www\project-front\.next\server\pages\proxy\login.js:19:7)
完整的堆栈跟踪here
我进行了研究,在 Google 或 Stackoverflow 上找不到像我这样的案例,我是 NextJS 的新手,所以我可能误解了一些东西。有人知道我做错了什么吗?
【问题讨论】:
标签: typescript api next.js typeerror