Added more pages to be revalidated
This commit is contained in:
parent
4fba3e19de
commit
4c9cf9f7c4
|
@ -1,14 +1,24 @@
|
||||||
/** @type {import('next').NextConfig} */
|
/** @type {import('next').NextConfig} */
|
||||||
|
|
||||||
|
/* CONFIG */
|
||||||
|
|
||||||
|
const locales = ["en", "fr", "ja", "es", "pt-br"];
|
||||||
|
|
||||||
|
/* END CONFIG */
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
swcMinify: true,
|
swcMinify: true,
|
||||||
reactStrictMode: true,
|
reactStrictMode: true,
|
||||||
i18n: {
|
i18n: {
|
||||||
locales: ["en", "fr", "ja", "es", "pt-br"],
|
locales: locales,
|
||||||
defaultLocale: "en",
|
defaultLocale: "en",
|
||||||
},
|
},
|
||||||
images: {
|
images: {
|
||||||
domains: ["img.accords-library.com"],
|
domains: ["img.accords-library.com"],
|
||||||
},
|
},
|
||||||
|
serverRuntimeConfig: {
|
||||||
|
locales: locales,
|
||||||
|
},
|
||||||
async redirects() {
|
async redirects() {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,13 +1,46 @@
|
||||||
import type { NextApiRequest, NextApiResponse } from "next";
|
import type { NextApiRequest, NextApiResponse } from "next";
|
||||||
|
import getConfig from "next/config";
|
||||||
|
|
||||||
export type RequestMailProps = {
|
export type RequestMailProps =
|
||||||
|
| HookRangedContent
|
||||||
|
| HookPostContent
|
||||||
|
| HookLibraryItem
|
||||||
|
| HookChronology;
|
||||||
|
|
||||||
|
export type HookRangedContent = {
|
||||||
event: "entry.update" | "entry.delete" | "entry.create";
|
event: "entry.update" | "entry.delete" | "entry.create";
|
||||||
model: string;
|
model: "ranged-content";
|
||||||
|
entry: {
|
||||||
|
library_item?: {
|
||||||
|
slug: string;
|
||||||
|
};
|
||||||
|
content?: {
|
||||||
|
slug: string;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export type HookPostContent = {
|
||||||
|
event: "entry.update" | "entry.delete" | "entry.create";
|
||||||
|
model: "post";
|
||||||
entry: {
|
entry: {
|
||||||
slug: string;
|
slug: string;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type HookLibraryItem = {
|
||||||
|
event: "entry.update" | "entry.delete" | "entry.create";
|
||||||
|
model: "library-item";
|
||||||
|
entry: {
|
||||||
|
slug: string;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export type HookChronology = {
|
||||||
|
event: "entry.update" | "entry.delete" | "entry.create";
|
||||||
|
model: "chronology-era" | "chronology-item";
|
||||||
|
};
|
||||||
|
|
||||||
export type ResponseMailProps = {
|
export type ResponseMailProps = {
|
||||||
message: string;
|
message: string;
|
||||||
revalidated: boolean;
|
revalidated: boolean;
|
||||||
|
@ -19,6 +52,7 @@ export default async function Mail(
|
||||||
) {
|
) {
|
||||||
console.log(req.body);
|
console.log(req.body);
|
||||||
const body = req.body as RequestMailProps;
|
const body = req.body as RequestMailProps;
|
||||||
|
const { serverRuntimeConfig } = getConfig();
|
||||||
|
|
||||||
// Check for secret to confirm this is a valid request
|
// Check for secret to confirm this is a valid request
|
||||||
if (
|
if (
|
||||||
|
@ -29,16 +63,67 @@ export default async function Mail(
|
||||||
.json({ message: "Invalid token", revalidated: false });
|
.json({ message: "Invalid token", revalidated: false });
|
||||||
}
|
}
|
||||||
|
|
||||||
const uRLsToRevalidate: string[] = [];
|
const paths: string[] = [];
|
||||||
|
|
||||||
if (body.model === "post") {
|
switch (body.model) {
|
||||||
uRLsToRevalidate.push(`/news/${body.entry.slug}`);
|
case "post": {
|
||||||
|
paths.push(`/news`);
|
||||||
|
paths.push(`/news/${body.entry.slug}`);
|
||||||
|
serverRuntimeConfig.locales?.map((locale: string) => {
|
||||||
|
paths.push(`/${locale}/news/${body.entry.slug}`);
|
||||||
|
paths.push(`/${locale}/news`);
|
||||||
|
});
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.table(uRLsToRevalidate);
|
case "library-item": {
|
||||||
|
paths.push(`/library`);
|
||||||
|
paths.push(`/library/${body.entry.slug}`);
|
||||||
|
serverRuntimeConfig.locales?.map((locale: string) => {
|
||||||
|
paths.push(`/${locale}/library/${body.entry.slug}`);
|
||||||
|
paths.push(`/${locale}/library`);
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case "chronology-era":
|
||||||
|
case "chronology-item": {
|
||||||
|
paths.push(`/wiki/chronology`);
|
||||||
|
serverRuntimeConfig.locales?.map((locale: string) => {
|
||||||
|
paths.push(`/${locale}/wiki/chronology`);
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case "ranged-content": {
|
||||||
|
if (body.entry.library_item) {
|
||||||
|
paths.push(`/library/${body.entry.library_item.slug}`);
|
||||||
|
paths.push(`/library/${body.entry.library_item.slug}/scans`);
|
||||||
|
}
|
||||||
|
serverRuntimeConfig.locales?.map((locale: string) => {
|
||||||
|
if (body.entry.library_item) {
|
||||||
|
paths.push(`/${locale}/library/${body.entry.library_item.slug}`);
|
||||||
|
paths.push(
|
||||||
|
`/${locale}/library/${body.entry.library_item.slug}/scans`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.table(paths);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
uRLsToRevalidate.map(async (url) => await res.unstable_revalidate(url));
|
Promise.all(
|
||||||
|
paths.map(async (path) => {
|
||||||
|
await res.unstable_revalidate(path);
|
||||||
|
})
|
||||||
|
);
|
||||||
return res.json({ message: "Success!", revalidated: true });
|
return res.json({ message: "Success!", revalidated: true });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// If there was an error, Next.js will continue
|
// If there was an error, Next.js will continue
|
||||||
|
|
Loading…
Reference in New Issue