infoalloggi-monorepo/apps/infoalloggi/src/pages/api/revalidation.ts
Marco Pedone 699579b432 feat: update environment variable handling and dependencies
- Added @t3-oss/env-nextjs for improved environment variable management.
- Updated zod to version 4.1.12 for enhanced validation capabilities.
- Upgraded jiti to version 2.6.1 for better module loading.
- Refactored environment variable imports from env.mjs to env.ts.
- Removed deprecated env.mjs file and replaced it with a new env.ts file using @t3-oss/env-nextjs.
- Adjusted various components and API routes to utilize the new environment variable structure.
- Updated next.config.js to support the new environment variable management.
- Modified Docker configuration to align with new BASE_URL handling.
2025-10-20 16:22:20 +02:00

31 lines
775 B
TypeScript

import type { NextApiRequest, NextApiResponse } from "next";
import { env } from "~/env";
export default async function handler(
req: NextApiRequest,
res: NextApiResponse,
) {
if (req.query.secret !== env.REVALIDATION_SECRET) {
return res.status(401).json({ message: "Invalid token" });
}
const path = decodeURIComponent(req.query.path as string);
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",
});
}
}