Compare commits
3 Commits
1552cc2013
...
37108217d8
Author | SHA1 | Date |
---|---|---|
Ryan Mwangi | 37108217d8 | |
Ryan Mwangi | 3d31d039d8 | |
Ryan Mwangi | e01c54e267 |
15
server.js
15
server.js
|
@ -168,10 +168,15 @@ END:VEVENT
|
||||||
`;
|
`;
|
||||||
});
|
});
|
||||||
icalString += `END:VCALENDAR`;
|
icalString += `END:VCALENDAR`;
|
||||||
|
|
||||||
fs.writeFileSync(filename, icalString);
|
fs.writeFileSync(filename, icalString);
|
||||||
|
|
||||||
// Generate a unique URL for the merged calendar
|
// Generate a unique URL for the merged calendar
|
||||||
const mergedCalendarUrl = `${req.protocol}://${req.get('host')}/${filename}`;
|
const mergedCalendarUrl = `http://localhost:3000/${filename}`;
|
||||||
|
|
||||||
|
// Store the merged calendar URL in a file
|
||||||
|
fs.writeFileSync(mergedCalendarUrlFile, mergedCalendarUrl);
|
||||||
|
|
||||||
console.log(`Merged calendar updated: ${mergedCalendarUrl}`);
|
console.log(`Merged calendar updated: ${mergedCalendarUrl}`);
|
||||||
|
|
||||||
|
|
||||||
|
@ -180,13 +185,19 @@ END:VEVENT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Schedule a cron job to update the merged calendar every hour
|
// Schedule a cron job to update the merged calendar every hour
|
||||||
cron.schedule('0 * * * *', () => {
|
cron.schedule('0 * * * *', () => {
|
||||||
console.log('Updating merged calendar...');
|
console.log('Updating merged calendar...');
|
||||||
updateMergedCalendar();
|
updateMergedCalendar();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// serve updated merged calendar to user
|
||||||
|
app.get('/merged-calendar', (req, res) => {
|
||||||
|
const mergedCalendarUrlFile = 'merged_calendar_url.txt';
|
||||||
|
const mergedCalendarUrl = fs.readFileSync(mergedCalendarUrlFile, 'utf8');
|
||||||
|
res.redirect(mergedCalendarUrl);
|
||||||
|
});
|
||||||
|
|
||||||
// Start the server
|
// Start the server
|
||||||
const port = 3000;
|
const port = 3000;
|
||||||
app.listen(port, () => {
|
app.listen(port, () => {
|
||||||
|
|
Loading…
Reference in New Issue