mortensen
mortensen

Reputation: 1237

Enable CORS in React app

I am setting up a React application that extracts from a public API. When I am testing the API in Postman, it works without problems. But if I use fetch() in my React app, I get a CORS error.

As far as I have understood, my client request should be allowed on the server using headers. But I don't own the server hosting the API, so I cannot do anything on the server. The API is configured to be used by third party applications using an access code, so I am a bit confused why it's not allowed to extract from the API in React.

What are my options?

Upvotes: 3

Views: 9798

Answers (2)

dbl4k
dbl4k

Reputation: 71

CORS is a security thing, under most circumstances the best practise would be not to try to allow the client to make callouts to wherever (the old clientside CORS * * * hackaroonie).

Instead, set up a simple serverside relay, as Tholle suggested above a middleman, in the same deployment (same origin).

There's a brief example of how you'd do this here.

Upvotes: 0

ehmad11
ehmad11

Reputation: 1395

if you don't have server access then you can bypass it

Upvotes: 1

Related Questions