Skip to content

Instantly share code, notes, and snippets.

@steinbring
Last active July 20, 2024 19:02
Show Gist options
  • Save steinbring/ff9c835ffa529ec143055394df310e00 to your computer and use it in GitHub Desktop.
Save steinbring/ff9c835ffa529ec143055394df310e00 to your computer and use it in GitHub Desktop.
A node proxy for getting the flavor of the day for the closest culver's locations to Milwaukee.
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request));
});
async function handleRequest(request) {
const url = 'https://www.culvers.com/api/locator/getLocations?lat=43.0386&long=-87.9067&radius=40233&limit=100&layer=';
try {
const response = await fetch(url);
const data = await response.json();
const locations = data.data.geofences.map(location => ({
Location: location.description,
Address: `${location.metadata.street}, ${location.metadata.city}, ${location.metadata.state}`,
Flavor: location.metadata.flavorOfDayName
}));
return new Response(JSON.stringify(locations), {
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': 'https://cdpn.io'
}
});
} catch (error) {
return new Response(JSON.stringify({ error: 'Failed to fetch data' }), {
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': 'https://cdpn.io'
},
status: 500
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment