diff --git a/src/app/api/revalidate/home/route.ts b/src/app/api/revalidate/home/route.ts new file mode 100644 index 0000000..dc2f335 --- /dev/null +++ b/src/app/api/revalidate/home/route.ts @@ -0,0 +1,27 @@ +import { revalidatePath } from 'next/cache'; +import { headers } from 'next/headers'; + +export async function POST() { + const headersList = await headers(); + const secret = headersList.get('X-Secret'); + + if (secret !== process.env.REVALIDATE_API_SECRET) { + return Response.json( + { + revalidated: false, + message: 'Invalid token', + }, + { status: 401 }, + ); + } + + revalidatePath('/'); + + return Response.json( + { + revalidated: true, + message: 'Revalidated /', + }, + { status: 200 }, + ); +} diff --git a/src/app/api/revalidate/job/route.ts b/src/app/api/revalidate/job/route.ts new file mode 100644 index 0000000..9d87cd0 --- /dev/null +++ b/src/app/api/revalidate/job/route.ts @@ -0,0 +1,27 @@ +import { revalidatePath } from 'next/cache'; +import { headers } from 'next/headers'; + +export async function POST() { + const headersList = await headers(); + const secret = headersList.get('X-Secret'); + + if (secret !== process.env.REVALIDATE_API_SECRET) { + return Response.json( + { + revalidated: false, + message: 'Invalid token', + }, + { status: 401 }, + ); + } + + revalidatePath('/job'); + + return Response.json( + { + revalidated: true, + message: 'Revalidated /job', + }, + { status: 200 }, + ); +} diff --git a/src/app/api/revalidate-memo/route.ts b/src/app/api/revalidate/memo/route.ts similarity index 100% rename from src/app/api/revalidate-memo/route.ts rename to src/app/api/revalidate/memo/route.ts diff --git a/src/app/api/revalidate/route.ts b/src/app/api/revalidate/route.ts deleted file mode 100644 index ea0e804..0000000 --- a/src/app/api/revalidate/route.ts +++ /dev/null @@ -1,52 +0,0 @@ -import { revalidatePath } from 'next/cache'; -import type { NextRequest } from 'next/server'; -import { z } from 'zod'; - -const TypeSchema = z.union([z.literal('page'), z.literal('layout')]).optional(); - -export async function GET(request: NextRequest) { - const searchParams = request.nextUrl.searchParams; - const secret = searchParams.get('secret'); - const path = searchParams.get('path'); - const type = TypeSchema.safeParse(searchParams.get('type')); - - if (secret !== process.env.REVALIDATE_API_SECRET) { - return Response.json( - { - revalidated: false, - message: 'Invalid token', - }, - { status: 401 }, - ); - } - - if (!path) { - return Response.json( - { - revalidated: false, - message: 'Missing path to revalidate', - }, - { status: 400 }, - ); - } - - if (!type.success) { - return Response.json( - { - revalidated: false, - message: 'Invalid type', - }, - { status: 400 }, - ); - } - - revalidatePath(path, type.data ?? undefined); - - return Response.json( - { - revalidated: true, - message: 'Revalidated', - }, - { status: 200 }, - ); -}