I have some static pages in my Next.js application (app router) that gets data from a database using Prisma. The data on those static pages change very rarely so the best option would be to manually revalidate it on demand. The solution I want to use works as expected locally: I make a build, open a page in a browser, update the DB data, run the route to revalidate, refresh the page and see the updated data. But it doesn’t work for the hosted app (App Platform), using the same process.
app -> (pages) -> my-page -> page.tsx
export default async function MyPage() {
const data = await getMyData();
return (
...show the data
);
}
app -> (pages) -> actions.ts
export async function getMyData() {
return await prisma.data.findMany({ orderBy: { order: 'asc' } });
}
app -> api -> revalidate -> route.ts
import { NextRequest, NextResponse } from 'next/server'
import { revalidatePath, revalidateTag } from 'next/cache'
export const dynamic = "force-dynamic";
export async function GET(request: NextRequest) {
const path = request.nextUrl.searchParams.get('path') ?? "/";
revalidatePath(path);
return NextResponse.json({ revalidated: path, now: Date.now() });
}
Example use of the revalidate route:
https://mysite.com/api/revalidate
https://mysite.com/api/revalidate?path=/(pages)/my-page
How to make on-demand revalidation not using the timing option? (export const revalidate
). Why does it work locally but not on DO?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!