We welcome your inquiries and support. Connect with us to learn more about our mission and how you can help enhance the lives of those affected by Muscular Dystrophy.
bottom of page
// backend/events.jsw
import { fetch } from 'wix-fetch';
import { getSecret } from 'wix-secrets-backend'; // if you need API keys
/**
* Fetch upcoming events from multiple sources.
* Swap out the example URLs with real API endpoints or RSS feeds.
*/
export async function getCommunityEvents() {
const events = [];
// --- Example: Eventbrite (requires API key) ---
// const EB_KEY = await getSecret("eventbriteApiKey");
// let resp = await fetch("https://www.eventbriteapi.com/v3/organizations/YOUR_ORG_ID/events/", {
// headers: { Authorization: `Bearer ${EB_KEY}` }
// });
// let data = await resp.json();
// data.events.forEach(e => {
// events.push({
// title: e.name.text,
// date: e.start.local,
// link: e.url
// });
// });
// --- Example: A site with JSON endpoint ---
try {
let resp2 = await fetch("https://example.org/api/upcoming-events");
if (resp2.ok) {
let list = await resp2.json(); // assume [{title, date, url}, …]
list.forEach(e => {
events.push({
title: e.title,
date: e.date,
link: e.url
});
});
}
} catch (err) {
console.error("Error fetching from example.org", err);
}
// --- Example: RSS feed parsing (XML) ---
try {
let resp3 = await fetch("https://another.org/events/rss.xml");
if (resp3.ok) {
let xml = await resp3.text();
// simple regex-based parsing – for production, use a proper XML parser
const itemRegex = /[\s\S]*?<\/item>/g;
let items = xml.match(itemRegex)||[];
items.forEach(item => {
let titleMatch = item.match(/<\/title>/);
let linkMatch = item.match(/(.*?)<\/link>/);
let dateMatch = item.match(/(.*?)<\/pubDate>/);
if (titleMatch && linkMatch && dateMatch) {
events.push({
title: titleMatch[1],
date: new Date(dateMatch[1]).toISOString(),
link: linkMatch[1]
});
}
});
}
} catch (err) {
console.error("Error parsing RSS feed", err);
}
// Sort by date
events.sort((a, b) => new Date(a.date) - new Date(b.date));
return events;
}