-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: add revalidatePath support to revalidate endpoint
- Loading branch information
Showing
4 changed files
with
128 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { revalidatePath } from "next/cache"; | ||
import { NextRequest, NextResponse } from "next/server"; | ||
|
||
const REVALIDATE_SECRET_TOKEN = process.env.CRAFT_REVALIDATE_SECRET_TOKEN; | ||
|
||
export async function GET(request: NextRequest): Promise<NextResponse> { | ||
const uri = request.nextUrl.searchParams.get("uri"); | ||
const secret = request.nextUrl.searchParams.get("secret"); | ||
|
||
if (!uri) { | ||
return NextResponse.json({ | ||
revalidated: false, | ||
now: Date.now(), | ||
message: "Missing path to revalidate", | ||
}); | ||
} | ||
|
||
if (secret !== REVALIDATE_SECRET_TOKEN) { | ||
return NextResponse.json({ | ||
revalidated: false, | ||
now: Date.now(), | ||
message: "Invalid token", | ||
}); | ||
} | ||
|
||
if (uri) { | ||
revalidatePath(`/[locale]/${uri}`, "page"); | ||
|
||
return NextResponse.json({ revalidated: true, now: Date.now() }); | ||
} | ||
|
||
return NextResponse.json({ | ||
revalidated: false, | ||
now: Date.now(), | ||
message: "Error revalidating", | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
/// <reference types="next" /> | ||
/// <reference types="next/image-types/global" /> | ||
/// <reference types="next/navigation-types/compat/navigation" /> | ||
|
||
// NOTE: This file should not be edited | ||
// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information. | ||
// see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters