javascript - getStaticProps 和 getServerSideProps 中的 fetch 是否与 native 浏览器 fetch API 相同?

标签 javascript node.js reactjs next.js fetch-api

我已经使用 Next.js 一段时间了,我怀疑 获取 API 用于getStaticPropsgetServerSideProps .
下面我写下我对getStaticProps的理解和 getServerSideProps :
获取静态属性 在构建时间和 ISR 期间被调用
获取服务器端属性 将在请求时被调用,但两者都无权访问客户端。
这是我对这些异步函数的理解。
所以我怀疑我们只写服务器端代码,Node.js 没有原生的 fetch API,那么 getStaticProps 里面使用了什么 fetch API和 getServerSideProps ?是原生获取 ?或者一些 填充 取名字?

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
    }
  }
}
真的很想知道是哪个获取 API 用来。

最佳答案

So my doubt is we only write server-side code and node.js doesn't have a native fetch API, so what fetch API is used inside getStaticProps and getServerSideProps?


在 Node.js 环境中(getStaticPropsgetServerSideProps 和 API 路由)Next.js 使用 node-fetchpolyfill the fetch API .

关于javascript - getStaticProps 和 getServerSideProps 中的 fetch 是否与 native 浏览器 fetch API 相同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68795872/

相关文章:

javascript - Angular 指令在函数后重复

javascript - 如何将 ENV 变量传递到脚本标记中

javascript - ECMAScript 2016 中的连接数组表达式

node.js - 在 MEAN 堆栈中创建搜索文章功能

node.js - 从 findElement(By.className()) 获取元素数组

reactjs - useHistory() react 钩子(Hook)似乎没有触发重新渲染

javascript - 开始使用 Durandal

node.js - 参数不起作用的快速路线

javascript - react 的 map 上没有点击事件

javascript - 在 React 和 Redux 中更新 props 而不留下函数