diff --git a/functions/requestcount.js b/functions/requestcount.js new file mode 100644 index 0000000..c026352 --- /dev/null +++ b/functions/requestcount.js @@ -0,0 +1,19 @@ +export const onRequest = async ({ env }) => { + const value = await fetch(env.TURSO_URL, { + method: "POST", + headers: { + Authorization: `Bearer ${env.TURSO_AUTH_TOKEN}`, + "Content-Type": "application/json", + }, + body: JSON.stringify({ + requests: [ + { type: "execute", stmt: { sql: "select count from request_count where id = 1" } }, + { type: "close" }, + ], + }), + }) + .then((res) => res.json()) + .then((res) => res.results[0].response.result.rows[0][0].value) + .catch((err) => console.log(err)); + return new Response(value, { status: 200 }); +} diff --git a/script.js b/script.js index 25becd8..abbf5b7 100644 --- a/script.js +++ b/script.js @@ -131,3 +131,9 @@ document.getElementById("go-now").addEventListener("click", () => { alert("Please enter an Unstoppable Domain to go to"); } }); + +document.addEventListener("DOMContentLoaded", (e) => { + const counter = document.getElementById("request-count"); + fetch("/requestcount").then(r => r.text()) + .then(r => counter.textContent = Number(r.trim()).toLocaleString()); +});