I'm attempting to call a webservice via POST from a create-react-app application to a local vhost running on XAMPP (also tried WAMP) with Windows 10 as the OS.
The local environments
http://test.local/
- Local server running on an XAMPP vhost.http://localhost:3000
- create react app url
What calls work in each circumstance
axios.get
responds correctly andaxios.post
responds correctly when made fromtest.local/
.axios.get
responds correctly andaxios.post
does not respond. when made from fromlocalhost:3000
The code used in my tests
axios.post
request that is failing from localhost:3000
axios.post('http://test.local/load/notifications/', { someData: 'someVal'},
{ headers: { "Access-Control-Allow-Origin": "*" }).then((resp) => {
console.log(resp.data); // no response in network tab of developer tools
}, (error) => {
// The request was made but no response was received
})
I've tried this request with and without the CORS setting in the configuration object.
PHP test file at test.local/load/notifications/index.php
<?php
header('Content-type: application/json');
header("Access-Control-Allow-Origin: *");
$mockDataFile = "./mockData.json";
$unencoded = json_decode(file_get_contents($mockDataFile));
echo json_encode($unencoded);
?>
My CORS header on the php page is set to
header("Access-Control-Allow-Origin: *");
, so I'm assuming it's not CORS related unless my syntax is off. There is no error message, the endpoint just doesn't return a response.
Directory flag in httpd.conf
<Directory />
AllowOverride none
Require local
Require ip 192.168.1.5
</Directory>
vhost configuration in httpd-vhosts.conf
:
<VirtualHost *:80>
DocumentRoot "F:\test\public"
<Directory "F:\test\public">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
</Directory>
ServerName test.local
ServerAlias test.local
CustomLog "logs/test.local-access.log" common
ErrorLog "logs/test.local-error.log"
</VirtualHost>