JS

JAVASCRIPT CORS FETCH WITH XAMPP

FOR WINDOWS - Windows\System32\drivers\etc\hosts   FOR MAC/LINUX -  etc/hosts

POINT SITE-A.COM & SITE-B.COM TO LOCAL IP ADDRESS 127.0.0.1 site-a.com 127.0.0.1 site-b.com

HOSTS FILE

01

ADD VIRTUAL HOSTS IN APACHE xampp\apache\conf\extra\httpd-vhosts.conf

VIRTUAL HOSTS

02

<VirtualHost *>   DocumentRoot "C:/sitea/"   ServerName site-a.com </VirtualHost>   <VirtualHost *>   DocumentRoot "C:/siteb/"   ServerName site-b.com </VirtualHost>

CORS FETCH

03

FIRE CORS FETCH ON SITE-A.COM fetch("http://site-b.com/cors.php") .then((res) =>    { return res.text(); }) .then((txt) =>    { console.log(txt); });

CORS RESPONSE

04

CORS ALLOWED ON ALL DOMAINS header("Access-Control-Allow-Origin:    *");   ALLOWED ONLY FOR SITE-A.COM header("Access-Control-Allow-Origin:   http://site-a.com");    OUTPUT echo "It works!";