mirror of
https://github.com/Shineii86/MiruroAPI.git
synced 2026-10-22 18:25:11 +00:00
Add no-cache headers to /random to prevent CDN caching
This commit is contained in:
@@ -320,11 +320,10 @@ const createApiRoutes = (jsonResponse, jsonError, startTime) => {
|
|||||||
// ---- FEATURE: Random anime of the day ----
|
// ---- FEATURE: Random anime of the day ----
|
||||||
router.get("/random", async (req, res) => {
|
router.get("/random", async (req, res) => {
|
||||||
try {
|
try {
|
||||||
// NOTE: Use multiple entropy sources for randomness in serverless
|
// NOTE: Disable CDN cache + use request timestamp for true randomness
|
||||||
const now = Date.now();
|
res.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
|
||||||
const hrtime = process.hrtime();
|
res.setHeader("Pragma", "no-cache");
|
||||||
const entropy = (now * 31 + hrtime[0] * 17 + hrtime[1] * 13) ^ (process.pid * 7);
|
const randomPage = (Date.now() % 499) + 1;
|
||||||
const randomPage = (Math.abs(entropy) % 499) + 1;
|
|
||||||
const data = await anilist.getCollection("POPULARITY_DESC", null, randomPage, 1);
|
const data = await anilist.getCollection("POPULARITY_DESC", null, randomPage, 1);
|
||||||
const anime = data.results[0];
|
const anime = data.results[0];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user