feat(WEB-104): add on-demand revalidation for cache
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
/* eslint-disable @next/next/no-css-tags */
|
||||
|
||||
import AdobeScript from "@/components/Current/AdobeScript"
|
||||
import Footer from "@/components/Current/Footer"
|
||||
import LangPopup from "@/components/Current/LangPopup"
|
||||
import Script from "next/script"
|
||||
import SkipToMainContent from "@/components/SkipToMainContent"
|
||||
import AdobeScript from "../AdobeScript"
|
||||
|
||||
import type { Metadata } from "next"
|
||||
import type { LangParams, LayoutArgs } from "@/types/params"
|
||||
@@ -21,8 +21,8 @@ export default function RootLayout({
|
||||
return (
|
||||
<html lang={params.lang}>
|
||||
<head>
|
||||
<link rel="stylesheet" href="/Static/css/core.css"/>
|
||||
<link rel="stylesheet" href="/Static/css/scandic.css"/>
|
||||
<link rel="stylesheet" href="/Static/css/core.css" />
|
||||
<link rel="stylesheet" href="/Static/css/scandic.css" />
|
||||
<Script
|
||||
data-cookieconsent="ignore"
|
||||
src="/Static/dist/js/cookie-bot.js?1705409331007"
|
||||
|
||||
@@ -30,13 +30,7 @@ export default async function CurrentPreviewPage({
|
||||
throw new Error("Not found")
|
||||
}
|
||||
|
||||
return (
|
||||
<ContentPage
|
||||
data={response.data}
|
||||
uri={searchParams.uri}
|
||||
lang={params.lang}
|
||||
/>
|
||||
)
|
||||
return <ContentPage data={response.data} />
|
||||
} catch (error) {
|
||||
// TODO: throw 500
|
||||
console.error(error)
|
||||
|
||||
45
app/api/revalidate/route.ts
Normal file
45
app/api/revalidate/route.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { env } from "@/env/server"
|
||||
import { revalidateTag } from 'next/cache'
|
||||
|
||||
import type { NextRequest } from 'next/server'
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const secret = request.nextUrl.searchParams.get("secret") ?? ""
|
||||
const tag = request.nextUrl.searchParams.get("tag") ?? ""
|
||||
|
||||
if (secret !== env.REVALIDATE_SECRET) {
|
||||
return Response.json(
|
||||
{
|
||||
message: 'Invalid secret',
|
||||
now: Date.now(),
|
||||
revalidated: false,
|
||||
},
|
||||
{
|
||||
status: 401,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
if (!tag) {
|
||||
return Response.json(
|
||||
{
|
||||
message: 'Missing tag param',
|
||||
now: Date.now(),
|
||||
revalidated: false,
|
||||
},
|
||||
{
|
||||
status: 400,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
revalidateTag(tag)
|
||||
|
||||
return Response.json({ revalidated: true, now: Date.now() })
|
||||
} catch (error) {
|
||||
console.info("Failed to revalidate tag")
|
||||
console.error(error)
|
||||
return Response.json({ revalidated: false, now: Date.now() }, { status: 500 })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user