Hi.
I have a seperate file named anilist.js which will have my fetch() request code. A small part of the code is like:
import fs from 'node:fs';
import path from 'node:path';
const url = 'https://graphql.anilist.co';
async function trending() {
const p = path.resolve(process.cwd(), './app/functions/trendingAnime.graphql');
const query = fs.readFileSync(p, 'utf-8');
const d = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
body: JSON.stringify({
query: query
})
}).then(res => res.json()).catch(err => console.error(err));
return d?.data?.Page?.media;
};
I'm importing the functions defined in this file to my page.jsx [It's not client]
What i want is, I wanna do the API call once every 60s or whatever time I wanna it to be. Currently, I just do an
const a = await trending()
Something like this in my page.jsx
How to make it so that it updates regularly in specific time interval without again building it as I host in VERCEL.
I checked docs but it gave me to directly use fetch() in the page.jsx which i wanna avoid if possible. Please help me on how to do this.
Thnx
did the