phongyewtong
phongyewtong

Reputation: 5309

Access to fetch at 'https://www.cloudflare.com/cdn-cgi/trace' from origin 'http://localhost:3000' has been blocked by CORS policy

How do i fix this?

let response = await fetch("https://www.cloudflare.com/cdn-cgi/trace", {
    // credentials: 'include',
    method: 'GET',
    // method: 'POST',
    headers: {'Content-Type': 'application/json'}
})

Access to fetch at 'https://www.cloudflare.com/cdn-cgi/trace' from origin 'http://localhost:3000' has been blocked by CORS policy: Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight response.

Upvotes: 1

Views: 2487

Answers (1)

Will Black
Will Black

Reputation: 402

You can try do it like this:

async function test () {
  let response = await fetch("https://www.cloudflare.com/cdn-cgi/trace", {mode: "cors"});
  let text = await response.text();
  console.log(text)
}
test()

Upvotes: 5

Related Questions