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!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Sign up for Infrastructure as a Newsletter.
Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Digital Ocean’s APP platform applies an additional level of cahcing through Cloudlfare. In these cases, requests made to
https://mysite.com/*
will actually be cached by cloudflare, and they will never reach your nextJs server, so they will never get the new content (until the age of the cache reaches the max-age defined in the Cache-Control header, which I believe is 1 year.DO says disabling this cache can be done by setting a Cache-control to no-cache in the responses of your server, but at the same time nextJS say this is not allowed
Not sure of a solution for this, other than don’t use NextJS + DO
Have you found any solution to that? I have pretty much same problem as you do. Wanted to use sanity webhooks to revalidate my content in next app but it works only localy.