Skip to content

Commit

Permalink
feat(api): ✨ Revalidation Url for ISR
Browse files Browse the repository at this point in the history
Incremental Static Regeneration with Data currently used in /faq and /teams. Other pages use ISR only with Translation aorn
  • Loading branch information
Nudelsuppe42 committed Aug 14, 2023
1 parent 415cc26 commit 1249bf8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
21 changes: 21 additions & 0 deletions src/pages/api/revalidate.ts
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);
}
2 changes: 1 addition & 1 deletion src/pages/faq/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const Faq: NextPage = ({ data }: any) => {

export default Faq;

export async function getServerSideProps({ locale }: any) {
export async function getStaticProps({ locale }: any) {
const res = await fetcher('/faq');
console.log(res?.length);

Expand Down
10 changes: 1 addition & 9 deletions src/pages/teams/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,7 @@ const Teams: NextPage = ({ data }: any) => {

export default Teams;

// export async function getStaticProps({ locale }: any) {
// return {
// props: {

// },
// };
// }

export async function getServerSideProps({ locale }: any) {
export async function getStaticProps({ locale }: any) {
const res = await fetcher('/buildteams');
console.log(res?.length);

Expand Down

0 comments on commit 1249bf8

Please sign in to comment.