የመጀመሪያው የሚሠራ ፋይል
public/app.js
ኮዱ እና የሚሠሩ ምሳሌ ገጾች የመጀመሪያ መለያዎቻቸውንና የምሳሌ ጽሑፋቸውን ይይዛሉ። ትምህርቱ እና የፋይል መመሪያዎች በእርስዎ ቋንቋ ያብራሯቸዋል።
document.querySelector("form").addEventListener("submit", async (e) => {
e.preventDefault();
const button = e.target.querySelector("button"),
status = document.querySelector("[role=status]");
button.disabled = true;
try {
const r = await fetch("/.netlify/functions/mini-mail", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + e.target.elements.access.value,
},
body: JSON.stringify({ name: e.target.elements.name.value }),
});
if (!r.ok) throw Error();
const value = await r.json();
status.textContent =
"Accepted by the mail provider. Check your test inbox. Reference: " + value.id;
} catch {
status.textContent =
"Could not request the email. Check the configured practice endpoint.";
} finally {
button.disabled = false;
}
});