问题
我有一个简单的next.js应用程序。在索引站点上,我有以下代码:
export async function getServerSideProps(ctx: NextPageContext) {
const json = await myGet("/api/people", ctx);
return {
props: {
people: json,
}, // will be passed to the page component as props
};
}myGet只使用url /api/people对api路由进行简单的提取(具有同构的提取)。但是,这个错误失败了:
服务器错误TypeError:只支持绝对URL
我的期望是,我可以使用类似于"/api/people“的路径,因为我使用相同的基url提供应用程序。在next.js中,我必须显式地提供完整的URL吗?(例如https://my-app/api/people)
Thx人
发布于 2022-10-10 10:33:16
在使用jest框架模拟API请求时,我得到了完全相同的错误,错误的原因是在功能中调用端点时出现了类型错误。
https://stackoverflow.com/questions/62242581
复制相似问题