【发布时间】:2021-10-18 02:15:55
【问题描述】:
我已经使用 Next.js 有一段时间了,我怀疑 getStaticProps 和 getServerSideProps 内部使用的 fetch API。
下面写下我对getStaticProps和getServerSideProps的理解:
getStaticProps 在构建时和 ISR 期间被调用
getServerSideProps 将在请求时被调用,但两者都无权访问客户端。
这是我对这些异步函数的理解。
所以我怀疑我们只编写服务器端代码而 Node.js 没有本机 fetch API,那么在 getStaticProps 和 getServerSideProps 中使用什么 fetch API?是 native fetch 吗?还是一些名为 fetch 的 polyfill?
async function getStaticProps(ctx){
// Which fetch API is this, browser fetch or some polyfill with same name as
fetch?
const data = fetch(.../..) // Some API
return {
props: {
data
}
}
}
async function getServerSideProps(ctx){
// ** Which fetch API is this, browser fetch or some polyfill with same name as
fetch?
const data = fetch(.../..) // **Some API**
return {
props: {
data
}
}
}
真的很想知道使用了哪个 fetch API。
【问题讨论】:
标签: javascript node.js reactjs next.js fetch-api