File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed
apps/next-blog/src/app/api/revalidate Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change 1- import { NextRequest , NextResponse } from 'next/server'
1+ import { NextRequest } from 'next/server'
22import { revalidatePath , revalidateTag } from 'next/cache'
33import { getAllPosts } from '../../../utils/blog'
4+ import { env } from '../../../env/server.mjs'
45
56export 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 }
You can’t perform that action at this time.
0 commit comments