diff --git a/app/api/revalidate/route.ts b/app/api/revalidate/route.ts index 9f7806d83..00f0f5929 100644 --- a/app/api/revalidate/route.ts +++ b/app/api/revalidate/route.ts @@ -1,36 +1,56 @@ -import { revalidateTag } from 'next/cache' import { NextRequest, NextResponse } from 'next/server' - -const REVALIDATE_SECRET = process.env.REVALIDATE_SECRET +import { revalidatePath, revalidateTag } from 'next/cache' export async function POST(request: NextRequest) { try { - const requestData = await request.json() - const { tag, secret } = requestData + const body = await request.json() + const { path, tag, secret } = body - // Check for secret if configured - if (REVALIDATE_SECRET && secret !== REVALIDATE_SECRET) { - return NextResponse.json({ message: 'Invalid revalidation token' }, { status: 401 }) + if (secret !== process.env.REVALIDATION_SECRET) { + return NextResponse.json({ message: 'Invalid secret' }, { status: 401 }) } - // Verify tag is provided - if (!tag) { - return NextResponse.json({ message: 'Missing tag parameter' }, { status: 400 }) + const timestamp = new Date().toISOString() + + if (path) { + // Revalidate specific path + revalidatePath(path) + console.log(`[ISR] Revalidated path: ${path} at ${timestamp}`) + return NextResponse.json({ + message: `Path ${path} revalidated successfully`, + timestamp, + type: 'path' + }) } - // Revalidate the tag - revalidateTag(tag) + if (tag) { + // Revalidate by tag + revalidateTag(tag) + console.log(`[ISR] Revalidated tag: ${tag} at ${timestamp}`) + return NextResponse.json({ + message: `Tag ${tag} revalidated successfully`, + timestamp, + type: 'tag' + }) + } - return NextResponse.json({ - revalidated: true, - message: `Tag "${tag}" revalidated successfully`, - timestamp: Date.now(), - }) + return NextResponse.json({ message: 'No path, tag, or type provided' }, { status: 400 }) } catch (error) { - console.error('Revalidation error:', error) + console.error('[ISR] Revalidation error:', error) return NextResponse.json( - { message: 'Error processing revalidation request', error: String(error) }, + { message: 'Error revalidating', error: error.message }, { status: 500 } ) } } + +// to check revalidation status +export async function GET() { + return NextResponse.json({ + message: 'ISR Revalidation API is active', + timestamp: new Date().toISOString(), + endpoints: { + POST: 'Trigger revalidation with { path, tag, secret }' + } + }) +} \ No newline at end of file diff --git a/app/docs/(main-docs)/[...slug]/page.tsx b/app/docs/(main-docs)/[...slug]/page.tsx index 08ea59017..63e7887b3 100644 --- a/app/docs/(main-docs)/[...slug]/page.tsx +++ b/app/docs/(main-docs)/[...slug]/page.tsx @@ -9,6 +9,8 @@ import { notFound } from 'next/navigation' import DocContent from '@/components/DocContent/DocContent' export const dynamicParams = false +export const revalidate = 0.5 * 60 * 60 // 30 minutes +export const dynamic = 'force-static' export async function generateMetadata({ params, @@ -62,6 +64,23 @@ export default async function Page({ params }: { params: { slug: string[] } }) { toc={toc} hideTableOfContents={hide_table_of_contents || false} /> + {/* TODO: remove this, debug info */} + { +
+
export revalidate: {revalidate}
+
Slug: {slug}
+
Generated: {new Date().toISOString()}
+
+ } ) } diff --git a/data/siteMetadata.js b/data/siteMetadata.js index 3924f629e..c253f41bc 100644 --- a/data/siteMetadata.js +++ b/data/siteMetadata.js @@ -6,7 +6,7 @@ const siteMetadata = { description: 'SigNoz is an open-source observability tool powered by OpenTelemetry. Get APM, logs, traces, metrics, exceptions, & alerts in a single tool.', language: 'en-us', - theme: 'dark', // system, dark or light + theme: 'dark', siteUrl: 'https://signoz.io', siteRepo: 'https://github.com/signoz/', siteLogo: '/img/logo.svg',