0

I am trying fetch status code of a http url. Whether 404 or 200.

This is the code

function App() {

  fetch(`https://www.google.com`).then((response) => {
    console.log(response); // returns 200
  });

  return (
    <div>
      <h4>Hello</h4>
    </div>
  );
}

export default App;

But in console I am getting this error,

Access to fetch at 'https://www.google.com/' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

How to solve this error and how to fetch status?

0 Answers0