Skip to content

Commit

Permalink
set response headers in api call
Browse files Browse the repository at this point in the history
  • Loading branch information
lucia-gomez committed Sep 21, 2024
1 parent ef4645c commit 28aa4db
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
10 changes: 8 additions & 2 deletions booking-app/app/api/calendarEvents/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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(
Expand Down
16 changes: 14 additions & 2 deletions booking-app/app/api/safety_training_users/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit 28aa4db

Please sign in to comment.