diff --git a/netlify/edge-functions/now-playing.js b/netlify/edge-functions/now-playing.js index 4925e739..5e2dde04 100644 --- a/netlify/edge-functions/now-playing.js +++ b/netlify/edge-functions/now-playing.js @@ -46,6 +46,13 @@ export default async () => { const TV_KEY = Netlify.env.get('API_KEY_TRAKT') // eslint-disable-next-line no-undef const MUSIC_KEY = Netlify.env.get('API_KEY_LASTFM') + const headers = { + headers: { + 'Content-Type': 'application/json', + 'Cache-Control': 'public, max-age=0, must-revalidate', + 'Netlify-CDN-Cache-Control': 'public, max-age=0, stale-while-revalidate=210', + }, + } const traktRes = await fetch('https://api.trakt.tv/users/cdransf/watching', { headers: { @@ -62,15 +69,21 @@ export default async () => { if (Object.keys(traktRes).length) { if (traktRes['type'] === 'episode') { - return Response.json({ - content: `📺 ${traktRes['show']['title']} • ${traktRes['episode']['title']}`, - }) + return Response.json( + { + content: `📺 ${traktRes['show']['title']} • ${traktRes['episode']['title']}`, + }, + headers + ) } if (traktRes['type'] === 'movie') { - return Response.json({ - content: `🎥 ${traktRes['movie']['title']}`, - }) + return Response.json( + { + content: `🎥 ${traktRes['movie']['title']}`, + }, + headers + ) } } @@ -113,10 +126,10 @@ export default async () => { if (isCorrectDate) { if (nowHour === startHour && nowMinutes >= startMinutes && nowHour < endHour) - return Response.json(res) + return Response.json(res, headers) if (nowHour > startHour && nowHour < endHour) return Response.json(res) if (nowHour > startHour && nowMinutes <= endMinutes && nowHour == endHour) - return Response.json(res) + return Response.json(res, headers) } } } @@ -158,11 +171,14 @@ export default async () => { genre = genreData.genres.sort((a, b) => b.count - a.count)[0]?.['name'] || '' } - return Response.json({ - content: `${emojiMap(genre, track['artist']['#text'])} ${ - track['name'] - } by ${track['artist']['#text']}`, - }) + return Response.json( + { + content: `${emojiMap(genre, track['artist']['#text'])} ${ + track['name'] + } by ${track['artist']['#text']}`, + }, + headers + ) } export const config = { path: '/api/now-playing' }