在InitialProps中获取数据

时间:2019-08-09 12:50:40

标签: reactjs fetch next.js prismic.io

由Reactjs,Nextjs和Prismic创建的用于管理后端数据的网站

我尝试将文章的内容放在文件的getInitialProps中,我恢复了通过文章的方式找到好文章的参数,在开发中我没有问题,但是当我要部署应用程序时错误

Blog.getInitialProps = async ({ query: { uid }, pathname }) => {
  const page = await Prismic.getApi(process.env.PRISMIC_API_ENDPOINT, {
    accessToken: process.env.PRISMIC_ACCESS_TOKEN
  }).then(function(api) {
    return api.getByUID('blog', uid)
  });
  return {
    page,
    uid,
    pathname
  }
};

实际上,当我启动npm run deploy时出现此错误:

Unable to encode undefined of type undefined 
    at q (/Applications/MAMP/htdocs/cotenature-com/node_modules/prismic-javascript/dist/prismic-javascript.min.js:1:10587)
    at Object.at (/Applications/MAMP/htdocs/cotenature-com/node_modules/prismic-javascript/dist/prismic-javascript.min.js:1:11859)
    at t.getByUID (/Applications/MAMP/htdocs/cotenature-com/node_modules/prismic-javascript/dist/prismic-javascript.min.js:1:3961)
    at /Applications/MAMP/htdocs/cotenature-com/.next/server/static/rZDgTUBaVKx0J4_TTzYMp/pages/blog/[uid].js:693:26
    at process._tickCallback (internal/process/next_tick.js:68:7)

谢谢

0 个答案:

没有答案