-1

I am making an application with ReactJS and PHP in the backend. Now React is listening to port 3000 and PHP to port 80. So when a POST request is made, it shows it is a cross-origin request.

To handle this I tried "proxy" in react but that did not work. After this, I thought to change the config of apache server and add port 3000 as well. To do this I followed this link here but it did not work.

This is the error I get ... Job for apache2.service failed because the control process exited with error code.

...

And when I remove the changes, it works fine. Please help. I am stuck here for hours now.

UPDATE The suggested solution in the as proposed duplicate works when I use fetch() but does not work when I use Axios. Can not figure out the reason for this.

1 Answers1

0

Change in /etc/apache2/apache2.conf

<Directory /var/www/html>
     Order Allow,Deny
     Allow from all
     AllowOverride all
     Header set Access-Control-Allow-Origin "*"
</Directory>

Add/activate module

 a2enmod headers 

Restart service

/etc/init.t/apache2 restart
Maikel
  • 300
  • 2
  • 11