Skip to content

Commit bf39927

Browse files
committed
disable caching
1 parent a1e2adc commit bf39927

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

api/lastfm.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
1-
// api/lastfm.js
21
export default async function handler(req, res) {
32
const USERNAME = "your-nemesis";
43
const API_KEY = process.env.LASTFM_API_KEY;
54

5+
res.setHeader("Cache-Control", "no-store, no-cache, must-revalidate, proxy-revalidate");
6+
res.setHeader("Pragma", "no-cache");
7+
res.setHeader("Expires", "0");
8+
res.setHeader("Surrogate-Control", "no-store");
9+
610
try {
711
const response = await fetch(
8-
`https://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=${USERNAME}&api_key=${API_KEY}&format=json`
12+
`https://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=${USERNAME}&api_key=${API_KEY}&format=json&nocache=${Date.now()}`
913
);
1014

1115
const data = await response.json();
1216
res.status(200).json(data);
1317
} catch (err) {
14-
console.error("Failed to fetch from LastFM:", err);
18+
console.error("Failed to fetch LastFM:", err);
1519
res.status(500).json({ error: "Failed to fetch Last.fm data" });
1620
}
1721
}

0 commit comments

Comments
 (0)