Last active
June 16, 2021 03:38
-
-
Save enesakar/02ea75c016d966a62078113b8e1b9771 to your computer and use it in GitHub Desktop.
aa.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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