I have Ubuntu 18.04 running with Apache and NodeJS server. The Apache server is listening on port 80 and 443. A PHP File is executed by the Apache server and is located at: http://server-ip/abc/index.php. It does a Post-Request to the NodeJS sever:
$postdata = http_build_query(
array(
'var1' => 'some content',
'var2' => 'doh'
)
);
$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-Type: application/x-www-form-urlencoded',
'content' => $postdata
)
);
$context = stream_context_create($opts);
$result = file_get_contents('http://127.0.0.1:8080/', false, $context);
//do something with $result
The NodeJS Server (script below) should read the Post-Parameters, do something with it an return a string.
var http = require('http');
http.createServer(function (req, res) {
//do something
//return something
}).listen(8080);
When the PHP Script tries to connect to the NodeJS server, i get the CORS same origin error.