Skip to content

Instantly share code, notes, and snippets.

@enesakar
Last active June 16, 2021 03:38
Show Gist options
  • Save enesakar/02ea75c016d966a62078113b8e1b9771 to your computer and use it in GitHub Desktop.
Save enesakar/02ea75c016d966a62078113b8e1b9771 to your computer and use it in GitHub Desktop.
aa.js
const endpoint = 'REPLACE_UPSTASH_REST_ENDPOINT'
const token = 'REPLACE_UPSTASH_REST_TOKEN'
async function recordRequest(request) {
let d = new Date();
let datestr = d.getFullYear() + "-" + (d.getMonth()+1) + "-" + d.getDate();
let data = [["url", request.url], ...request.headers]
let url = endpoint + '/lpush/' + datestr
const init = {
body: JSON.stringify(data),
method: "POST",
headers: {
"Authorization": "Bearer " + token
},
}
return await fetch(url, init);
}
async function handleRequest(request) {
recordRequest(request);
return new Response("My Awesome Website");
}
addEventListener("fetch", (event) => {
event.respondWith(
handleRequest(event.request).catch(
(err) => new Response(err.stack, { status: 500 })
)
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment