Skip to content

Commit

Permalink
Revalidation doesn't work for multi-language site #689
Browse files Browse the repository at this point in the history
  • Loading branch information
pmi committed Aug 17, 2023
1 parent 12025c7 commit d93da2a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export async function middleware(req: NextRequest) {
if (
req.nextUrl.pathname.startsWith('/_next') ||
req.nextUrl.pathname.includes('/api/') ||
req.nextUrl.pathname.startsWith('/_/enonic') ||
PUBLIC_ASSET.test(req.nextUrl.pathname)
) {
return
Expand All @@ -29,4 +30,4 @@ export async function middleware(req: NextRequest) {
}

return NextResponse.next();
}
}
15 changes: 11 additions & 4 deletions src/pages/api/revalidate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ interface ResponseData {
message: string
}

export default async function handler(req: NextApiRequest,
res: NextApiResponse<ResponseData>) {
export default async function handler(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
const {token, path} = req.query;
// Check for secret to confirm this is a valid request
if (token !== process.env.ENONIC_API_TOKEN) {
Expand All @@ -21,8 +20,16 @@ export default async function handler(req: NextApiRequest,
console.info('Started revalidating everything...');
const projectId = req.headers[PROJECT_ID_HEADER] as string | undefined;
const config = getLocaleProjectConfigById(projectId);
const paths = await fetchContentPathsForLocale('\${site}/', config!);
const promises = paths.map((item: ContentPathItem) => revalidatePath(res, item.params.contentPath));
const paths = await fetchContentPathsForLocale('\${site}/', config);
const promises = paths.map((item: ContentPathItem) => {
const cp = item.params.contentPath;
if (cp[0] === "") {
cp[0] = config.locale;
} else {
cp.unshift(config.locale);
}
return revalidatePath(res, cp);
});
await Promise.all(promises);
console.info(`Done revalidating everything`);
} else {
Expand Down

0 comments on commit d93da2a

Please sign in to comment.