Skip to content

Commit

Permalink
test adding encodeURIComponent and decodeURIComponent to revalidate
Browse files Browse the repository at this point in the history
  • Loading branch information
kahlstrm committed Jan 23, 2024
1 parent c2008c5 commit 4d4181e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
6 changes: 3 additions & 3 deletions apps/cms/src/hooks/revalidate-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ export const revalidatePage =
const fetchUrl = `${
process.env.PUBLIC_FRONTEND_URL
}/next_api/revalidate?${new URLSearchParams({
secret: revalidationKey,
collection,
fetchData,
secret: encodeURIComponent(revalidationKey),
collection: encodeURIComponent(collection),
fetchData: encodeURIComponent(fetchData),
}).toString()}`;
req.payload.logger.info(
`sending revalidate request ${fetchUrl.replace(revalidationKey, "REDACTED")}`,
Expand Down
12 changes: 9 additions & 3 deletions apps/web/src/app/next_api/revalidate/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ import { NextResponse } from "next/server";
// this is to achieve on-demand revalidation of pages that use this data
// send either `collection` and `slug` or `revalidatePath` as query params
export function GET(request: NextRequest): NextResponse {
const collection = request.nextUrl.searchParams.get("collection");
const fetchData = request.nextUrl.searchParams.get("fetchData");
const secret = request.nextUrl.searchParams.get("secret");
const collection = decodeURIComponent(
request.nextUrl.searchParams.get("collection") ?? "",
);
const fetchData = decodeURIComponent(
request.nextUrl.searchParams.get("fetchData") ?? "",
);
const secret = decodeURIComponent(
request.nextUrl.searchParams.get("secret") ?? "",
);

if (secret !== process.env.NEXT_REVALIDATION_KEY) {
// eslint-disable-next-line no-console -- for debugging purposes
Expand Down

0 comments on commit 4d4181e

Please sign in to comment.