Reputation: 49
I am trying to get the domain from the request in nodejs, the request originates from PHP and when I get origin in Nodejs I get undefined.
This is my code in PHP: (domain1.com)
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://myNodedomain.com/sendAlert',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HEADER => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => array('token' => '3242342332'),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
This is my code in NodeJs: (mynodedomain.com)
app.post('/sendAlert', async (req, res) => {
console.log(req.get('host'));
console.log(req.get('origin'));
});
The desired result is: https://domain1.com/
Any solution?
Upvotes: 0
Views: 149
Reputation: 51
I'm not super familiar with PHP, but adding something like this might work:
curl_setopt($curl, CURLOPT_HTTPHEADER, ['Origin: domain1.com']);
Upvotes: 2