# Cannot fetch the games from RAWG's API. ...has been blocked by CORS policy

**URL:** <https://forum.codewithmosh.com/t/cannot-fetch-the-games-from-rawgs-api-has-been-blocked-by-cors-policy/19349>\
**Category:** React\
**Created:** [April 4, 2023, 10:27am UTC](https://forum.codewithmosh.com/t/cannot-fetch-the-games-from-rawgs-api-has-been-blocked-by-cors-policy/19349 "2023-04-04T10:27:38Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![herrifransisca](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/herrifransisca/32/953_2.png) [@herrifransisca](https://forum.codewithmosh.com/u/herrifransisca)\
**Post date:** [April 4, 2023, 10:27am UTC](https://forum.codewithmosh.com/t/cannot-fetch-the-games-from-rawgs-api-has-been-blocked-by-cors-policy/19349/1 "2023-04-04T10:27:38Z")

</div>

Hi Everyone,

I’m stuck on video: Project- Building a Video Games Discovery App- Fetching the Games.

here’s the error message showed on the browser:  
Access to XMLHttpRequest at ‘[https://api.rawg.io/api/games?key=ee56abc41bf2421fa1df42aabed3xxxx](https://api.rawg.io/api/games?key=ee56abc41bf2421fa1df42aabed3xxxx)’ from origin ‘[http://localhost:5173](http://localhost:5173)’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.

Thank you for your help /\

---

<div class="post-metadata">

**Author:** ![herrifransisca](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/herrifransisca/32/953_2.png) [@herrifransisca](https://forum.codewithmosh.com/u/herrifransisca)\
**Post date:** [April 4, 2023, 10:37am UTC](https://forum.codewithmosh.com/t/cannot-fetch-the-games-from-rawgs-api-has-been-blocked-by-cors-policy/19349/2 "2023-04-04T10:37:07Z")

</div>

Hi,

I’ve found the problem.

The problem is on my RAWG’s API account, The Number of requests left for the period is -2412.

Note:  
I think because I forgot to put dependency when calling useEffect()

---

<div class="post-metadata">

**Author:** ![santyago](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/santyago/32/1289_2.png) [@santyago](https://forum.codewithmosh.com/u/santyago)\
**Post date:** [April 19, 2023, 2:03pm UTC](https://forum.codewithmosh.com/t/cannot-fetch-the-games-from-rawgs-api-has-been-blocked-by-cors-policy/19349/3 "2023-04-19T14:03:17Z")

</div>

You can try creating a new account, don’t forget to add the square brackets in useEffect previously.

---

<div class="post-metadata">

**Author:** ![Jim](https://avatars.discourse-cdn.com/v4/letter/j/ac91a4/32.png) [@Jim](https://forum.codewithmosh.com/u/Jim)\
**Post date:** [May 23, 2023, 1:14am UTC](https://forum.codewithmosh.com/t/cannot-fetch-the-games-from-rawgs-api-has-been-blocked-by-cors-policy/19349/4 "2023-05-23T01:14:56Z")

</div>

I’m having the same issue, i created a new account but looks like its going the same direction.

Could anyone provide a code snippet of the effect hook usage in this project? Or let me know how/why my app is firing so many requests to the API?

Thanks,  
Jim

---

<div class="post-metadata">

**Author:** ![BlotCoo](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/blotcoo/32/5976_2.png) [@BlotCoo](https://forum.codewithmosh.com/u/BlotCoo)\
**Post date:** [May 23, 2023, 2:55am UTC](https://forum.codewithmosh.com/t/cannot-fetch-the-games-from-rawgs-api-has-been-blocked-by-cors-policy/19349/5 "2023-05-23T02:55:31Z")

</div>

Like mentioned above you may not be passing the square brackets`[]` as an optional second parameter to your effect hook. If you don’t include that it can run infinitely.

---

<div class="post-metadata">

**Author:** ![Jim](https://avatars.discourse-cdn.com/v4/letter/j/ac91a4/32.png) [@Jim](https://forum.codewithmosh.com/u/Jim)\
**Post date:** [May 23, 2023, 8:59am UTC](https://forum.codewithmosh.com/t/cannot-fetch-the-games-from-rawgs-api-has-been-blocked-by-cors-policy/19349/7 "2023-05-23T08:59:18Z")

</div>

in this line?

useEffect( () =\> {

---

<div class="post-metadata">

**Author:** ![BlotCoo](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/blotcoo/32/5976_2.png) [@BlotCoo](https://forum.codewithmosh.com/u/BlotCoo)\
**Post date:** [May 23, 2023, 1:20pm UTC](https://forum.codewithmosh.com/t/cannot-fetch-the-games-from-rawgs-api-has-been-blocked-by-cors-policy/19349/8 "2023-05-23T13:20:55Z")

</div>

It’ll be something like `useEffect(() => {...}, []);`

---

<div class="post-metadata">

**Author:** ![Jim](https://avatars.discourse-cdn.com/v4/letter/j/ac91a4/32.png) [@Jim](https://forum.codewithmosh.com/u/Jim)\
**Post date:** [May 28, 2023, 10:40am UTC](https://forum.codewithmosh.com/t/cannot-fetch-the-games-from-rawgs-api-has-been-blocked-by-cors-policy/19349/9 "2023-05-28T10:40:57Z")

</div>

yep found it, thanks mate!

---

<div class="post-metadata">

**Author:** ![MorningDa](https://avatars.discourse-cdn.com/v4/letter/m/ecb155/32.png) [@MorningDa](https://forum.codewithmosh.com/u/MorningDa)\
**Post date:** [October 25, 2023, 6:06am UTC](https://forum.codewithmosh.com/t/cannot-fetch-the-games-from-rawgs-api-has-been-blocked-by-cors-policy/19349/10 "2023-10-25T06:06:59Z")

</div>

I’ve encountered that CORS error before, and it can be pretty frustrating. Usually, it’s a security feature to protect against unauthorized requests. To fix it, you might need to configure your API to allow requests from your local host. I did that to play the [free dominoes game app](https://wealthofgeeks.com/apps-that-pay-you-to-play-games/). Don’t worry; you’ll get past this hiccup and keep building your Video Games Discovery App!

---

<div class="post-metadata">

**Author:** ![greecepowerball](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/greecepowerball/32/7171_2.png) [@greecepowerball](https://forum.codewithmosh.com/u/greecepowerball)\
**Post date:** [October 25, 2023, 4:40pm UTC](https://forum.codewithmosh.com/t/cannot-fetch-the-games-from-rawgs-api-has-been-blocked-by-cors-policy/19349/11 "2023-10-25T16:40:41Z")

</div>

You can resolve the CORS issue by setting up a server-side proxy to make the API request or by checking the API documentation for required headers or keys.  
Greece Powerball results

---

<div class="post-metadata">

**Author:** ![blitzoc](https://avatars.discourse-cdn.com/v4/letter/b/6bbea6/32.png) [@blitzoc](https://forum.codewithmosh.com/u/blitzoc)\
**Post date:** [October 26, 2023, 10:37am UTC](https://forum.codewithmosh.com/t/cannot-fetch-the-games-from-rawgs-api-has-been-blocked-by-cors-policy/19349/12 "2023-10-26T10:37:46Z")

</div>

did you resolve it finally?  
i have the same problem.  
but on my account i still have 19997 requests left. that is whats written there…

added now also the (still having that many requests left) but its still not working.  
so is there anything i can do concerning the client-side?
