Skip to content

Commit

Permalink
Return event timestamp and check clientside
Browse files Browse the repository at this point in the history
  • Loading branch information
riccardobl committed May 16, 2024
1 parent 805e86b commit 5d41d3b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ async function loop(){
const eventsToPost = [];
const response = await fetch(`${PROXY_ADDRESS}/get?secret=${PROXY_SECRET}`);
const events = await response.json();
events.forEach((event) => {
console.log("Found", events.length, "events")
for(const event of events){
if(event.timestamp > LAST_EVENT){
eventsToPost.push(event);
eventsToPost.push(event.event);
LAST_EVENT=event.timestamp;
}
});
};
console.log("Posting", eventsToPost.length, "events")
await Promise.allSettled(eventsToPost.map(async (event) => {
console.log("Propagating event", event);
return fetch(WEBHOOK_ADDRESS, {
method: "POST",
headers: {
Expand Down
7 changes: 6 additions & 1 deletion src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ app.get("/get", (req, res) => {
});
res.json(EVENTS.filter((event) => {
return event.secret === secret;
}).map((event) => event.event));
}).map((event) => {
return {
event: event.event,
timestamp: event.timestamp
}
}));
});

if (SERVER_CRT && SERVER_KEY) {
Expand Down

0 comments on commit 5d41d3b

Please sign in to comment.