Home>

As the title says.
According to the error messageAccess-Control-Allow-OriginSet the header or set to modecorsI tried to set, but the same error was output.

Is there a way to get around it?

I would appreciate it if you could teach me.

fetch ('https://api.twitter.com/2/users/by/username/piyo', {
      method:'GET',
      mode:'cors',
      headers: {
        Authorization: hoge,
        'Access-Control-Allow-Origin':'*',
      },
    }). then (response =>{
      console.log (response.json ());
    });
Access to fetch at'https://api.twitter.com/2/users/by/username/piyo' from origin'http: // localhost: 3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: 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.
  • Answer # 1

    According to the error messageAccess-Control-Allow-OriginSet the header

    Access-Control-Allow-OriginThe header isServer sideIs what you set. Setting it on the client side has no effect.

    Is there a way to get around it?

    Since it is not appropriate to put the key for Twitter on the Web that anyone can see and the server side does not allow processing, there is no way to handle it only with client side JavaScript.