我在我的Next.js项目中使用了新的App Router。我的页面充满了从桶中获取的Markdown文件的内容。在我的Vercel主机上,这些页面被永久缓存,因此对Markdown文件的更改不会显示。
文档显示了如何在fetch
参数中指定缓存过期时间。但是我的函数没有使用fetch
,它使用的是Firebase SDK。
我还尝试添加一个额外的步骤,创建一个返回文件内容的内部API路由,然后页面路由可以fetch
该api路由,指定适当的重新验证参数。但是Next.js似乎不允许从服务器端获取内部API路由。
下面是我的一个路由的代码,其中downloadFromStorage
返回bucket中文件的内容。
import {TextPage} from "@/components";
import {downloadFromStorage} from "@/app/api/file-handling";
export default async function PageTerms(props) {
const text=await downloadFromStorage('pages/terms.md')
return (<TextPage text={text.toString()}/>)
}
(the downloadFromStorage
函数)
import {storage} from "./firebase"
export async function downloadFromStorage(filename, bucketName = BUCKET) {
const bucket = storage.bucket(bucketName);
const file = bucket.file(filename);
return new Promise((resolve, reject) => {
file.download((err, contents) => {
if (err) {
reject(err);
return;
}
resolve(contents);
});
});
}
1条答案
按热度按时间hivapdat1#
您可以使用
revalidate
选项添加路由段配置。这将根据导出的整数重新验证整个段。您可以在官方文档中了解有关段配置和重新验证选项的更多信息。