isr on demand fixed.

This commit is contained in:
Hikmet 2023-07-22 12:00:31 +03:00
parent c7eae15a96
commit 65f17fdc2d
4 changed files with 25 additions and 22 deletions

View File

@ -324,7 +324,7 @@ export function useAdminViewModel(): AdminViewModel {
const publishChanges = async () => {
setStalling(true);
const resObj = await fetch(`/api/admin/temalar`, {
const resObj = await fetch(`/api/admin/temalar/${themeId}`, {
method: "POST",
body: JSON.stringify({ type: "publishChanges" }),
headers: {

View File

@ -35,6 +35,29 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
const theme = req.query.theme as string;
const themeData = await themeRepo.getThemeData(theme);
return res.status(200).json(themeData);
} else if (req.method === "POST") {
const { type } = req.body;
const themeId = req.query.theme;
if (type === "publishChanges") {
try {
await res.revalidate(`/temalar/${themeId}`);
await res.revalidate("/");
return res.status(200).send({
status: "success",
message: "Değişiklikler başarıyla yayınlandı.",
});
} catch (error) {
console.error(
`/api/admin/temalar/${themeId} -> POST -> publishChanges ->`,
error
);
return res.status(200).send({
status: "error",
message: "Değişikliklerin yayınlanması başarısız.",
});
}
}
}
return res.status(501).json({ error: "Unsopported request method" });

View File

@ -27,26 +27,6 @@ export default async function handler(
return res.status(200).json(result.data);
}
return res.status(200).json([]);
} else if (req.method === "POST") {
const { type } = req.body;
if (type === "publishChanges") {
try {
await res.revalidate("/temalar/[theme]");
return res.status(200).send({
status: "success",
message: "Değişiklikler başarıyla yayınlandı.",
});
} catch (error) {
console.error(error);
return res.status(200).send({
status: "error",
message: "Değişikliklerin yayınlanması başarısız.",
});
}
}
return res.status(501).json({ error: "Unsopported action" });
}
return res.status(501).json({ error: "Unsopported request method" });

View File

@ -28,5 +28,5 @@ export async function getStaticPaths() {
return { paths: themePaths, fallback: false };
}
return { paths: [{ params: { theme: "id1234" } }], fallback: false };
return { paths: [], fallback: false };
}