2025-10-17 19:14:27 +02:00
|
|
|
import type { NextApiRequest, NextApiResponse } from "next";
|
2025-10-20 16:22:20 +02:00
|
|
|
import { env } from "~/env";
|
2025-10-17 19:14:27 +02:00
|
|
|
|
|
|
|
|
export default async function handler(
|
|
|
|
|
req: NextApiRequest,
|
|
|
|
|
res: NextApiResponse,
|
|
|
|
|
) {
|
|
|
|
|
if (req.query.secret !== env.REVALIDATION_SECRET) {
|
|
|
|
|
return res.status(401).json({ message: "Invalid token" });
|
|
|
|
|
}
|
2025-10-17 19:48:28 +02:00
|
|
|
const path = decodeURIComponent(req.query.path as string);
|
2025-10-17 19:14:27 +02:00
|
|
|
|
|
|
|
|
if (!path) {
|
|
|
|
|
return res.status(400).json({ message: "Missing path parameter" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
await res.revalidate(`${path}`);
|
|
|
|
|
|
|
|
|
|
return res.json({
|
|
|
|
|
success: true,
|
|
|
|
|
message: `Page ${path} revalidated successfully`,
|
|
|
|
|
});
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error("Error revalidating:", err);
|
|
|
|
|
return res.status(500).json({
|
|
|
|
|
success: false,
|
|
|
|
|
message: err instanceof Error ? err.message : "Unknown error",
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|