-
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.
feat(api): ✨ Revalidation Url for ISR
Incremental Static Regeneration with Data currently used in /faq and /teams. Other pages use ISR only with Translation aorn
- Loading branch information
1 parent
415cc26
commit 1249bf8
Showing
3 changed files
with
23 additions
and
10 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,21 @@ | ||
import type { NextApiRequest, NextApiResponse } from 'next'; | ||
|
||
export default async function handler(req: NextApiRequest, res: NextApiResponse) { | ||
if (req.query.secret !== process.env.NEXTAUTH_SECRET) return res.status(401).json({ message: 'Invalid secret' }); | ||
|
||
if (!req.query.path && !req.query.paths) return res.status(400).json({ message: 'Missing path' }); | ||
|
||
const paths = JSON.parse((req.query.paths as string) || `["${req.query.path}"]`); | ||
|
||
paths.map(async (path: string) => { | ||
try { | ||
await res.revalidate(path); | ||
console.log(`[${new Date().toISOString()}] Revalidated ${path}`); | ||
return { revalidated: true, path }; | ||
} catch (err) { | ||
return { revalidated: false, path }; | ||
} | ||
}); | ||
|
||
return res.json(paths); | ||
} |
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