Answer the question
In order to leave comments, you need to log in
Why does Cloudflare Worker throw an error when trying to parse JSON?
There is a code:
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
/**
* Respond to the request
* @param {Request} request
*/
async function handleRequest(request) {
const url = new URL(request.url)
try{
let quotes = JSON.parse(
await(await fetch('https://raw.githubusercontent.com/bonsoirelliot/navalny-rest/quotes/quotes1.json')).text()
)
const randomQuote = quotes[Math.floor(Math.random() * quotes.length)]
return new Response(randomQuote, {status: 200})
}catch(error){
print(error)
}
}
Answer the question
In order to leave comments, you need to log in
You have a JSON curve, there is a comma before the closing bracket.
Well, the print function in JS is Window.print() by default, which prints the current page in the browser.
try calling the snippet uncached.
In general, pdoTools has fastfield tags.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question