Remove CORS issue in reactjs

Pramodkumar
Jun 2, 2023

--

CORS is implemented on the server-side; it cannot be reconfigured on the client-side. The CORS behavior, commonly termed as CORS error, is a mechanism to restrict users from accessing shared resources.

This is not an error but a security measure to secure users or the website which you are accessing from a potential security breach.

This breach may occur due to incomplete or improper HTTP headers on the client-side implementation (eg. missing authorization data such as API key).

Avoid CORS Errors

In package.json add the origin for which api you want to call e.g. origin is https://joke-api-strict-cors-appspot.com. Add proxy as shown below

That’s it now fetch api using the end points as shown below

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Pramodkumar
Pramodkumar

No responses yet

Write a response