Loutag
Loutag

Reputation: 93

Next.js On-Demand Revalidation from server side (express)

I would like to know what is the best way to revalidate on-demand specific static pages from my server side (express), in my case it's after having created/updated/deleted a category.

I know that according to Next documentation I have to create a file : client/pages/api/revalidate.js that will handle it. But have I to call it from my express server-side (categoryController.js) :

  try {
    await axios.get(
      `http://localhost:3000/api/revalidate?secret=${process.env.REVALIDATE_TOKEN}`
    );
    console.log("successfully revalidated");
    res.status(200).json();
  } catch (error) {
    throw error;
  }

Or is there another proper way to do that ? Thank you for your help !

Upvotes: 2

Views: 655

Answers (0)

Related Questions