Error while connecting heroku server with my React App

184 views Asked by At

I am tired to resolve my error when I am connected my front end React App with my Heroku server App and when I fire a request from my front-end so that time I am getting this issue:

Failed to load https://hidden-reaches-90171.herokuapp.com/GETDATA: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access.

Can anyone face this issue sol please guide me what I am doing wrong, Thanks

1

There are 1 answers

0
SabirAmeen On

Try the following code on your main server file in nodejs.

app.all('/*', function(request, response, next) {
  response.header("Access-Control-Allow-Origin", "*");
  response.header('Access-Control-Allow-Methods', 'GET, PUT, POST, DELETE, OPTIONS');
  response.header('Access-Control-Allow-Headers', 'Origin, Content-Type, Accept');
  if (request.method == 'OPTIONS') {
    response.status(200).end();
  } else {
    next();
  }
});