Is there a way to simulate a server endpoint so that each time a user accesses the API, extra properties are added to the response?
For example, initially the endpoint returns:
[{id: 1, price:null}]
Then, with each subsequent call, it adds new information like this: [{id: 1, price: 10}]
I attempted using setTimeout for this purpose, but it didn't work as expected because the frontend is hitting the endpoint every second and re-executing the function.
const data = [/*...*/];
let loading;
function load() {
for(const el of data)
el.score = Math.random();
}
app.get("/api/", (req, res) => {
if(!loading) loading = setTimeout(load, 5000);
res.json({ data });
});