Question

Next.js revalidatePath works on local build but not in App Platform

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?


Submit an answer


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!

Sign In or Sign Up to Answer

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

card icon
Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Sign up
card icon
Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We’d like to help.

Learn more
card icon
Become a contributor

You get paid; we donate to tech nonprofits.

Learn more
Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow – whether you’re running one virtual machine or ten thousand.

Learn more ->
DigitalOcean Cloud Control Panel