mirror of
https://github.com/supleed2/udlink-docs.git
synced 2024-11-09 11:59:32 +00:00
Add request count logic and element update
This commit is contained in:
parent
2ef06644f2
commit
45c94dc0be
19
functions/requestcount.js
Normal file
19
functions/requestcount.js
Normal file
|
@ -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 });
|
||||
}
|
|
@ -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());
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue