I'm setting up a new notification server with nodejs and socket.io. The server it is working, with postman I can send a POST request and indeed sends the notification but with PHP it's taking for ages to send the POST with curl and it's not really working
The nodejs server is running on debian 9, I got a SSL certificate from let's encrypt so it's authenticated, like I said before with postman ( https://www.getpostman.com/ ) I can make the POST request and works. I'm sending headers with a secret key and body with data to the notification
#!/usr/bin/env node
var fs = require('fs');
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const port = process.env.PORT || 49152;
const notificationSecret = process.env.NOTIFICATION_SECRET;
var server;
if(process.env.SSL_KEY && process.env.SSL_CERT) {
var options = {
key: fs.readFileSync(process.env.SSL_KEY_PATH),
cert: fs.readFileSync(process.env.SSL_CERT_PATH)
};
server = require('https').createServer(options, app);
} else {
console.log("Error creating the server, missing KEY OR CERT");
}
const io = require('socket.io')(server);
server.listen(port, () => console.log('Server listening at port %d', port));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(express.static(__dirname + '/public'));
app.post('/send', (req, res) => {
... more but not important
and PHP
$data = array("notification" => "IF THIS WORKS", "channel" => "myChannel");
$payload = json_encode($data);
// Prepare new cURL resource
$ch = curl_init('IP/send');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
// Set HTTP Header for POST request
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'notification_secret: ')
);
// Submit the POST request
$result = curl_exec($ch);
// Close cURL session handle
curl_close($ch);
Anyone has any idea what can I try to fix it?