From ecd4b3835c8e2e20fac1f95e601a306d2f4a99de Mon Sep 17 00:00:00 2001 From: Ryan Mwangi Date: Fri, 18 Oct 2024 16:43:13 +0300 Subject: [PATCH] serve the merged calendar file --- server.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/server.js b/server.js index a1818d0..30553e8 100644 --- a/server.js +++ b/server.js @@ -97,7 +97,7 @@ END:VEVENT // Save the user input and generated ID in calendars.json file saveCalendarData(calendarId, calendars); - + // Save the user input in a calendars.json file const calendarsFile = 'calendars.json'; let calendarsData = {}; @@ -129,6 +129,14 @@ END:VEVENT res.status(500).json({ error: 'Failed to merge calendars' }); } }); + +// Serve the merged calendar file +app.get('/calendar/:id', (req, res) => { + const filename = `${req.params.id}.ics`; + res.setHeader('Content-Type', 'text/calendar'); + res.sendFile(filename, { root: MERGED_CALENDARS_DIR }); +}); + //function to save CalendarData to calendars.json function saveCalendarData(calendarId, calendars) { let calendarsData = { mergedCalendars: [] };