| 2 | import { NextRequest, NextResponse } from "next/server"; |
| 3 | |
| 4 | export async function GET(req: NextRequest) { |
| 5 | const fromQuery = req.nextUrl.searchParams.get("secret"); |
| 6 | const path = req.nextUrl.searchParams.get("path"); |
| 7 | |
| 8 | if (fromQuery != process.env.MY_SECRET_TOKEN) { |
| 9 | return NextResponse.json({ message: "Invalid token" }, { status: 401 }); |
| 10 | } |
| 11 | try { |
| 12 | if (path) { |
| 13 | revalidatePath(path); |
| 14 | return NextResponse.json({ revalidated: true, now: Date.now() }); |
| 15 | } |
| 16 | } catch (e) { |
| 17 | return NextResponse.json({ message: "Error revalidating" }, { status: 500 }); |
| 18 | } |
| 19 | } |