We have a Node JS - Express application running on a Openshift RHC v2 and an api is being called to a third party SMS gateway server whenever a user requests for an OTP. For this we have added a simple $http call which will trigger an SMS to the mentioned number with the message.
The request looks something like this :
$http.get("http://example.com/?user=userid:password&number=9876543210&message='Hi your OTP is 18276'")
.success(function(error, response){
if (!error && response.statusCode == 200) {
console.log('STATUS: ' + response.statusCode)
console.log('HEADERS: ' + JSON.stringify(response.headers));
} else {
console.log('STATUS : '+ error.statusCode);
console.log(error);
}
});
This works as soon as the RHC Server starts running. After a few days or sometimes a few hours we observe that this API is never called. We have added console logs before and after the requests and still the API is never called. It is very very surprising and shocking how can it not execute this request (which is working for a few days and then goes down completely).
What could be the issue here? Will re-share what we have :
console.log("Generated OTP : " + otp); // ... Where OTP is what we have generated... Console 1
var number = 9876543210;
var message = 'Hi your OTP is : '+otp;
console.log('Number : ' + number + ', Message : ' + message); // ... Console 2
$http.get("http://example.com/?user=userid:password&number="+number+"&message="+message)
.success(function(error, response){
if (!error && response.statusCode == 200) {
console.log('STATUS: ' + response.statusCode) ... Console 3
console.log('HEADERS: ' + JSON.stringify(response.headers)); // ... Console 4
} else {
console.log('STATUS : '+ error.statusCode); // ... Console 5
console.log(error); // ... Console 6
}
});
console.log("callback - Post - /sellers/phone/:number/:email"); // ...Console 7
res.json({"otp":otp});
When this is down, Consoles 1, 2 and 7 can be seen but not 3, 4 or 5 and 6.
Is there any way we can debug either on the Openshift or on the Node application?
If I do a server restart using rhc app-restart <app>
the other consoles will be seen and we receive the SMS / Messages.
Please help. Any additional information needed, please let us know. Thank you.
EDIT : I have also tried using request as below :
request(url, function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log('STATUS: ' + response.statusCode);
console.log('HEADERS: ' + JSON.stringify(response.headers));
} else {
console.log('STATUS : ' + error.statusCode);
console.log(error);
}
});