Skip to content

Commit ac606ef

Browse files
authored
Merge pull request #147 from TrialAndErrorOrg/tfk/revalidate-blog-properly
fix: allow revalidation of all pages
2 parents ddcc284 + c4c606f commit ac606ef

File tree

1 file changed

+13
-2
lines changed
  • apps/next-blog/src/app/api/revalidate

1 file changed

+13
-2
lines changed

apps/next-blog/src/app/api/revalidate/route.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1-
import { NextRequest, NextResponse } from 'next/server'
1+
import { NextRequest } from 'next/server'
22
import { revalidatePath, revalidateTag } from 'next/cache'
33
import { getAllPosts } from '../../../utils/blog'
4+
import { env } from '../../../env/server.mjs'
45

56
export async function GET(request: NextRequest) {
67
const path = request.nextUrl.searchParams.get('path')
8+
const layout = Boolean(request.nextUrl.searchParams.get('layout'))
9+
const token = request.headers.get('x-revalidation-token')
10+
11+
if (token !== env.NEXT_REVALIDATION_TOKEN) {
12+
return new Response('Invalid token', { status: 401 })
13+
}
714

815
if (path) {
9-
revalidatePath(path)
16+
revalidatePath(path, layout ? 'layout' : 'page')
1017
return new Response(`Revalidated path: ${path}`)
1118
}
1219

@@ -24,6 +31,10 @@ export async function POST(request: NextRequest) {
2431
const token = request.headers.get('x-revalidation-token')
2532
const body = await request.json()
2633

34+
if (token !== env.NEXT_REVALIDATION_TOKEN) {
35+
return new Response('Invalid token', { status: 401 })
36+
}
37+
2738
if (!body) {
2839
return new Response('No body provided')
2940
}

0 commit comments

Comments
 (0)