From 28aa4dbe6365a884bb33d798b0a6002d85320fc2 Mon Sep 17 00:00:00 2001 From: lucia <51058748+lucia-gomez@users.noreply.github.com> Date: Fri, 20 Sep 2024 20:42:43 -0400 Subject: [PATCH] set response headers in api call --- booking-app/app/api/calendarEvents/route.ts | 10 ++++++++-- .../app/api/safety_training_users/route.ts | 16 ++++++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/booking-app/app/api/calendarEvents/route.ts b/booking-app/app/api/calendarEvents/route.ts index e5c5eaad..11db3bce 100644 --- a/booking-app/app/api/calendarEvents/route.ts +++ b/booking-app/app/api/calendarEvents/route.ts @@ -5,8 +5,8 @@ import { updateEventPrefix, } from "@/components/src/server/calendars"; -import { serverBookingContents } from "@/components/src/server/admin"; import { getCalendarClient } from "@/lib/googleClient"; +import { serverBookingContents } from "@/components/src/server/admin"; const getCalendarEvents = async (calendarId: string) => { const calendar = await getCalendarClient(); @@ -84,7 +84,13 @@ export async function GET(req: NextRequest) { try { const events = await getCalendarEvents(calendarId); - return NextResponse.json(events); + const res = NextResponse.json(events); + res.headers.set( + "Cache-Control", + "no-store, no-cache, must-revalidate, proxy-revalidate", + ); + res.headers.set("Expires", "0"); + return res; } catch (error) { console.error("Error fetching calendar events:", error); return NextResponse.json( diff --git a/booking-app/app/api/safety_training_users/route.ts b/booking-app/app/api/safety_training_users/route.ts index fcc62919..33c3bbd3 100644 --- a/booking-app/app/api/safety_training_users/route.ts +++ b/booking-app/app/api/safety_training_users/route.ts @@ -57,14 +57,26 @@ export async function GET(request: NextRequest) { const rows = response.data.values; if (!rows || rows.length === 0) { - return NextResponse.json({ emails: [] }); + const res = NextResponse.json({ emails: [] }); + res.headers.set( + "Cache-Control", + "no-store, no-cache, must-revalidate, proxy-revalidate", + ); + res.headers.set("Expires", "0"); + return res; } const emails = rows .flat() .filter(email => email && typeof email === "string"); - return NextResponse.json({ emails }); + const res = NextResponse.json({ emails }); + res.headers.set( + "Cache-Control", + "no-store, no-cache, must-revalidate, proxy-revalidate", + ); + res.headers.set("Expires", "0"); + return res; } catch (error) { console.error("Failed to fetch emails:", error); if (