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
addEventListener('fetch', event => { | |
event.respondWith(handleRequest(event.request)) | |
}) | |
async function handleRequest(request) { | |
const response = await fetch( | |
request.url.replace("https://fonts.jirafe.io", "https://fonts.googleapis.com"), | |
request | |
); |
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
addEventListener("fetch", event => { | |
const response = new Response(`{"country":"${event.request.headers.get("cf-ipcountry")}"}`, { | |
headers: { | |
"Access-Control-Allow-Origin": "*", | |
"Content-Type": "application/json" | |
} | |
}) | |
event.respondWith(response) | |
}) |
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 apiKey = (async () => { | |
const buffer = await crypto.subtle.digest( | |
"SHA-256", | |
new TextEncoder("utf-8").encode( | |
window.crypto.getRandomValues(new Uint8Array(32)) | |
) | |
); | |
return Array.prototype.map | |
.call(new Uint8Array(buf), x => ("00" + x.toString(16)).slice(-2)) |
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
function useGreetings(language) { | |
const [greetings, setGreetings] = useState() | |
// 1. language changes (render) | |
// 2. useEffect triggers (post-render) | |
// 3. greetings are updated (render) | |
useEffect(() => { | |
switch (language) { | |
case "fr": { | |
setGreetings(["salut", "bonjour"]) |