Commit 95a73401 authored by Oleg Nikolaev's avatar Oleg Nikolaev
Browse files

MAX-21: Add on demand revalidation example

Additional configuration required
parent feb7db4c
Loading
Loading
Loading
Loading
+32 −0
Original line number Diff line number Diff line
// TODO: remove hardcode, replicate, settings for different brands

import { CACHE_TAGS } from "../../../../lib/constants/cache-tags";

export default {
  afterCreate(event) {
    if (event?.result.publishedAt) {
      fetch("http://localhost:3000/api/revalidate-tag", {
        method: "POST",
        body: JSON.stringify({ tags: [CACHE_TAGS.testDrivePage] }),
      });
    }
  },

  afterDelete(event) {
    if (event?.result.publishedAt) {
      fetch("http://localhost:3000/api/revalidate-tag", {
        method: "POST",
        body: JSON.stringify({ tags: [CACHE_TAGS.testDrivePage] }),
      });
    }
  },

  afterUpdate(event) {
    if (event?.result.publishedAt) {
      fetch("http://localhost:3000/api/revalidate-tag", {
        method: "POST",
        body: JSON.stringify({ tags: [CACHE_TAGS.testDrivePage] }),
      });
    }
  },
};
+5 −0
Original line number Diff line number Diff line
export const CACHE_TAGS = {
  testDrivePage: "test-drive-page",
  corporateSalesPage: "corporate-sales-page",
  insurancePage: "insurance-page",
} as const;