Skip to content

Commit

Permalink
Merge pull request #57 from atiqurx/main
Browse files Browse the repository at this point in the history
disable caching for events api
  • Loading branch information
atiqurx authored Oct 4, 2024
2 parents dcad406 + 4cba837 commit 193d85c
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/app/api/events/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import axios from 'axios';
import axios from "axios";
import { Event } from "@/lib/types";

// Define the type for the Google Calendar API event
Expand All @@ -9,9 +9,8 @@ interface GoogleCalendarEvent {
dateTime?: string; // Use string because Google Calendar returns dateTime as a string
date?: string; // All-day event date
};
location?: string;
location?: string;
}

export async function GET(req: Request) {
const GOOGLE_CALENDAR_ID = process.env.GOOGLE_CALENDAR_ID;
const CALENDAR_API_KEY = process.env.CALENDAR_API_KEY;
Expand All @@ -26,30 +25,35 @@ export async function GET(req: Request) {

// Map to extract the specific information
const modifiedEvents: Event[] = events.map((event) => {

const startDateTime = event.start.dateTime ? new Date(event.start.dateTime) :
(event.start.date ? new Date(event.start.date) : undefined);
const startDateTime = event.start.dateTime
? new Date(event.start.dateTime)
: event.start.date
? new Date(event.start.date)
: undefined;

return {
id: event.id,
title: event.summary,
start: startDateTime,
location: event.location,
location: event.location,
};
});

// Add Cache-Control: no-store to ensure no caching
return new Response(JSON.stringify(modifiedEvents), {
status: 200,
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
"Cache-Control": "no-store", // Disable caching for fresh data
},
});
} catch (error) {
console.error('Error fetching events:', error);
return new Response(JSON.stringify({ error: 'Failed to fetch events' }), {
console.error("Error fetching events:", error);
return new Response(JSON.stringify({ error: "Failed to fetch events" }), {
status: 500,
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
"Cache-Control": "no-store", // Disable caching for error responses as well
},
});
}
Expand Down

0 comments on commit 193d85c

Please sign in to comment.