0

I am deploying my first app on heroku. (It's a node.js/react app.) The app has deployed successfully, but when I try to login I get this error:

Access to XMLHttpRequest at 'https://<myApp>.herokuapp.com/users' from origin 
'https://<myApp>-front-end.herokuapp.com' 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.

I know other answers explain how to fix this problem with a proxy url, but I am wondering whether I did something wrong in the first place. Following an online tutorial, I deployed the front end and back end separately, and that seems to be causing the problem. Should I have deployed the front end and back end together to avoid this problem? Or is getting around this problem a normal part of deploying an app?

Brian Embry
  • 71
  • 2
  • 7
  • https://.herokuapp.com/users & https://-front-end.herokuapp.com both have backends. They’re separate servers running at different origins. You happen to have frontend JavaScript code running at https://-front-end.herokuapp.com that’s making a request to https://.herokuapp.com/users. So maybe what you’re describing instead is that you have an API endpoint running at https://.herokuapp.com/users and you’re wondering if that API endpoint should run on the same server that’s the backend for https://-front-end.herokuapp.com. If so the answer is, it depends – sideshowbarker Oct 30 '18 at 09:56

0 Answers0