Skip to content

Commit bd12092

Browse files
committed
test
1 parent d8def66 commit bd12092

File tree

2 files changed

+58
-20
lines changed

2 files changed

+58
-20
lines changed

app/api/revalidate/route.ts

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,56 @@
1-
import { revalidateTag } from 'next/cache'
21
import { NextRequest, NextResponse } from 'next/server'
3-
4-
const REVALIDATE_SECRET = process.env.REVALIDATE_SECRET
2+
import { revalidatePath, revalidateTag } from 'next/cache'
53

64
export async function POST(request: NextRequest) {
75
try {
8-
const requestData = await request.json()
9-
const { tag, secret } = requestData
6+
const body = await request.json()
7+
const { path, tag, secret } = body
108

11-
// Check for secret if configured
12-
if (REVALIDATE_SECRET && secret !== REVALIDATE_SECRET) {
13-
return NextResponse.json({ message: 'Invalid revalidation token' }, { status: 401 })
9+
if (secret !== process.env.REVALIDATION_SECRET) {
10+
return NextResponse.json({ message: 'Invalid secret' }, { status: 401 })
1411
}
1512

16-
// Verify tag is provided
17-
if (!tag) {
18-
return NextResponse.json({ message: 'Missing tag parameter' }, { status: 400 })
13+
const timestamp = new Date().toISOString()
14+
15+
if (path) {
16+
// Revalidate specific path
17+
revalidatePath(path)
18+
console.log(`[ISR] Revalidated path: ${path} at ${timestamp}`)
19+
return NextResponse.json({
20+
message: `Path ${path} revalidated successfully`,
21+
timestamp,
22+
type: 'path'
23+
})
1924
}
2025

21-
// Revalidate the tag
22-
revalidateTag(tag)
26+
if (tag) {
27+
// Revalidate by tag
28+
revalidateTag(tag)
29+
console.log(`[ISR] Revalidated tag: ${tag} at ${timestamp}`)
30+
return NextResponse.json({
31+
message: `Tag ${tag} revalidated successfully`,
32+
timestamp,
33+
type: 'tag'
34+
})
35+
}
2336

24-
return NextResponse.json({
25-
revalidated: true,
26-
message: `Tag "${tag}" revalidated successfully`,
27-
timestamp: Date.now(),
28-
})
37+
return NextResponse.json({ message: 'No path, tag, or type provided' }, { status: 400 })
2938
} catch (error) {
30-
console.error('Revalidation error:', error)
39+
console.error('[ISR] Revalidation error:', error)
3140
return NextResponse.json(
32-
{ message: 'Error processing revalidation request', error: String(error) },
41+
{ message: 'Error revalidating', error: error.message },
3342
{ status: 500 }
3443
)
3544
}
3645
}
46+
47+
// to check revalidation status
48+
export async function GET() {
49+
return NextResponse.json({
50+
message: 'ISR Revalidation API is active',
51+
timestamp: new Date().toISOString(),
52+
endpoints: {
53+
POST: 'Trigger revalidation with { path, tag, secret }'
54+
}
55+
})
56+
}

app/docs/(main-docs)/[...slug]/page.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { notFound } from 'next/navigation'
99
import DocContent from '@/components/DocContent/DocContent'
1010

1111
export const dynamicParams = false
12+
export const revalidate = 0.5 * 60 * 60 // 30 minutes
1213

1314
export async function generateMetadata({
1415
params,
@@ -62,6 +63,23 @@ export default async function Page({ params }: { params: { slug: string[] } }) {
6263
toc={toc}
6364
hideTableOfContents={hide_table_of_contents || false}
6465
/>
66+
{/* TODO: remove this, debug info */}
67+
{
68+
<div className="cache-debug" style={{
69+
position: 'fixed',
70+
bottom: '10px',
71+
right: '10px',
72+
background: 'rgba(0,0,0,0.8)',
73+
color: 'white',
74+
padding: '10px',
75+
fontSize: '12px',
76+
borderRadius: '4px'
77+
}}>
78+
<div>export revalidate: {revalidate}</div>
79+
<div>Slug: {slug}</div>
80+
<div>Generated: {new Date().toISOString()}</div>
81+
</div>
82+
}
6583
</div>
6684
)
6785
}

0 commit comments

Comments
 (0)