0

I'm having quite a basic issue I suppose. I've set up CraftCMS to be reachable via Apache Virtual Host http://craftapi and am using Element API with routes such as http://craftapi/projects?page=1 etc.

On a separate Virtual Host http://mysite I've set up a react-static install which should fetch the JSON using Axios from http://craftapi/projects?page=1 but it throws after Importing routes from directory... with:

Error: socket hang up

Am I not allowed to fetch from a different domain? Even if it is hosted on the same server?

Thanks

riccardolardi
  • 1,713
  • 5
  • 20
  • 35
  • You can either enable CORS for your apis (http://craftapi/...), or create a proxy for your apis on the (http://mysite) so that all the request `http://mysite/api/*` is forwared to `http://craftapi/*` – Sujeet Jaiswal Dec 10 '19 at 11:48
  • Thanks @SujeetJaiswal. Also I found this https://create-react-app.dev/docs/proxying-api-requests-in-development/ – riccardolardi Dec 10 '19 at 13:26

0 Answers0