[英]What is the best practice to fetch non-api data in Next.js(deploying through Vercel)
I am trying to fetch my own data before rendering my application.我试图在呈现我的应用程序之前获取我自己的数据。 Fortunately, Next.js provides
getStaticProps()
for fetching data.幸运的是, Next.js提供了
getStaticProps()
来获取数据。
I am currently using fs
module to fetch my data from json file in local directory.我目前正在使用
fs
模块从本地目录中的 json 文件中获取我的数据。
export async function getStaticProps() {
const rawData = fs.readFileSync('./dataset/test.json');
const data = modifyData(JSON.parse(rawData));
return {
props: {
data
}
}
}
But the problem is, for securing my raw data, I didn't push them to the GitHub remote repository.但问题是,为了保护我的原始数据,我没有将它们推送到 GitHub 远程存储库。 Forgetting this, when I tried to deploy my app through vercel, it couldn't read any data from my GitHub repository as the repository does not contain any data to fetch from...
忘记这一点,当我尝试通过 vercel 部署我的应用程序时,它无法从我的 GitHub 存储库中读取任何数据,因为存储库不包含任何要从中获取的数据......
I don't want to push my raw data to GitHub.我不想将我的原始数据推送到 GitHub。
I would like to know我想知道
If there are some fundamentals of Next.js or any other I missed, please let me know and correct me.如果有 Next.js 的一些基础知识或我遗漏的任何其他内容,请告诉我并纠正我。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.