Avoid 'Remote request only' error Message when Node Server access domain - javascript

Using Node.js, I am trying to send a GET request to server and I've used the following code for that.
const https = require('https');
https.get('https://example-domain-name/', (resp) => {
let data = '';
// A chunk of data has been recieved.
resp.on('data', (chunk) => {
data += chunk;
});
// The whole response has been received. Print out the result.
resp.on('end', () => {
console.log(data);
});
}).on("error", (err) => {
console.log("Error: " + err.message);
});
The problem is that, the server is responding statusCode 500 (Runtime error).
An application error occurred on the server. The current custom error
settings for this application prevent the details of the application
error from being viewed remotely (for security reasons). It could,
however, be viewed by browsers running on the local server machine.
But browser is displaying the page normally, but using node js request, i get the something following response data(text).
How to avoid this and normally request and response data like browser using node.js?
Please Help... StackOverFlow is only my basis of help now!!

Related

Running JavaScript with a web request?

BACK STORY :
Let me come from my problem, I need to update firebase database with Arduino so I used firebase-Arduino library but for some reason it will not compile Node MCU so my next way is a bit complicated that is I created a java script to update the firebase I just need to add 1 to the database so I don't need to update sensor value or anything so if I load the webpage it will update the value ,I thought it will be triggered with http request from Arduino but I was wrong it does not work like that.
QUESTION : How to run the JavaScript in a webpage with a web request from Arduino?
Assuming you have node.js installed you can have something like this (source):
const https = require('https');
https.get('your_url_here', (resp) => {
let data = '';
// A chunk of data has been recieved.
resp.on('data', (chunk) => {
data += chunk;
});
// The whole response has been received. Print out the result.
resp.on('end', () => {
console.log(JSON.parse(data).explanation);
});
}).on("error", (err) => {
console.log("Error: " + err.message);
});
But if you don't have installed node.js you might create the http request from bash commands like curl. This can be useful since you can make it run as daemon (run on th background every X minutes).
Let me know if you managed, something good luck.

Too many requests from nodejs server causes "connect EADDRNOTAVAIL"

In my Node server (running on Mac), I'm requesting data from an external API using websockets and sending the result I get to my cloud API.
The websocket is sending a lot of data (1000+ obj/s). When I try to POST this to my cloud server, I get error on client side (my node server). This only happens during high load, I get no errors when load is lower (say 300/s). I'm not POSTing to my local server so I don't know what this error means.
One thing I noticed is that the ports are not reused. When I have high load, I go up to 15000+ used ports on my local machine and then I start getting these errors.
I have tried setting "agent: false" in the HTTP header without success. I have also tried "connection": "keep-alive" without success (found these two suggestions on SO).
This is the code that is POSTing the data I get from websocket:
function PostCode(codestring, apipathstring) {
return new Promise((resolve,reject)=>{
// An object of options to indicate where to post to
var post_options = {
host: 'hostname', //
port: 'port',
path: apipathstring,
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(post_data),
}
};
// Set up the request
var post_req = https.request(post_options,function(res){
let data = '';
res.setEncoding('utf8');
// A chunk of data has been recieved.
res.on('data', (chunk) => {
data += chunk;
});
// The whole response has been received. Print out the result.
res.on('end', () => {
resolve(data);
});
// Error event received
}).on("error", (err) => {
reject("POSTING Error: " + err);
});
post_req.write(post_data);
post_req.end();
})
}
Optimally, I would stream even high traffic data without getting these connection errors.
Errors below:
Error: connect EADDRNOTAVAIL [my_cloud_IP] - Local (0.0.0.0:0)
Error: getaddrinfo ENOTFOUND [my_cloud_IP] [my_cloud_IP]:[my_cloud_port]
You can create your own "keep alive" agent, and use that one specific agent to send all the HTTP requests:
const http = require('http');
const keepAliveAgent = new http.Agent({ keepAlive: true });
options.agent = keepAliveAgent;
http.request(options, onResponseCallback);
According to the document:
keepAlive Keep sockets around even when there are no outstanding requests, so they can be used for future requests without having to reestablish a TCP connection.

Struggling to perform a "simple" HTTP GET using Node.js - Destination Server Using TLS 1.0

I'm struggling to perform a "simple" HTTP GET using Node.js
I've done some digging, and I feel the error may stem from the Server Using TLS 1.0?
Below is a simple block of code to replicate the issue.
I'm using Node v10.9.0
const https = require('https');
https.get('https://supplychain.2go.com.ph', (resp) => {
let data = '';
resp.on('data', (chunk) => {
data += chunk;
});
resp.on('end', () => {
console.log(data);
});
}).on("error", (err) => {
console.log("Error: " + err.message);
});
The error returned is:
Client network socket disconnected before secure TLS connection was established
I have tried a number of things such as adding options:
rejectUnauthorized:false
I've also tried the same thing with axios and the request library. Both yield the same negative results.
I have no control over the sever end, so I cannot alter the TLS setting
Thank you for taking the time to read - Any help would be greatly appreciated.

Cant make http request with intent

So I'm currently trying to have an intent trigger an http request but keep getting errors.
When the intent triggers this code is executed
const https = require('https');
https.get('*************',
(resp) => {
let data = '';
resp.on('data', (chunk) => {
data += chunk;
});
resp.on('end', () => {
console.log(JSON.parse(data).explanation);
});
}).on("error", (err) => {
console.log("Error: " + err.message);
});
When running the intent I get Error: getaddrinfo ENOTFOUND back
My code works fine when I run it locally so the issue appears to be something not lining up properly with dialogflow
If anyone has any advice I would greatly appreciate it.
Thanks!
Dialogflow fulfillments are hosted as firebase cloud functions. Firebase free plan only allows Google service API. If you want to use an external API, you will have to upgrade your plan.
More information can be found here https://firebase.google.com/pricing/

Dialogflow Webhook (Webhook call failed. Error: 500 Internal Server Error)

I've followed this tutorial's code (https://dialogflow.com/docs/getting-started/basic-fulfillment-conversation) to return results of an API to dialog flow. However my webhook keeps failing. Can someone help me figure out why?
Here's one of the failed conversations:
Here's my code:
'use strict';
const http = require('http');
exports.Hadoop = (req, res) => {
// Get name node server from the request
let nameNodeServer = req.body.queryResult.parameters['nameNodeServer']; // nameNodeServer is a required param
// Call the Hadoop API
getNameNodeInfo(nameNodeServer).then(function(output) {
res.json({ 'fulfillmentText': output }); // Return the results to Dialogflow
}).catch(() => {
res.json({ 'fulfillmentText': 'getNameNodeInfo() Error'- });
});
};
function getNameNodeInfo (nameNodeServer) {
return new Promise((resolve, reject) => {
// Create url for the HTTP request to get the name node info
let url = 'http://' + nameNodeServer + '[rest of url]';
// Make the HTTP request to get the name node info
http.get(url, (res) => {
let body = ''; // var to store the response chunks
res.on('data', (chunk) => {body += chunk; });
res.on('end', () => {
// After all the data has been received, parse the JSON for desired data
let response = JSON.parse(body);
let beans = response['beans'][0];
// Create response
let output = `Percent Used: ${beans['PercentUsed']}`;
// Resolve the promise with the output text
console.log(output);
resolve(output);
});
res.on('error', (error) => {
console.log(`Error calling the Hadoop API: ${error}`);
reject();
});
});
});
}
I believe the getNameNodeInfo function and the retrieval of the name node server are correct, as they logged the correct output in debugging.
Diagnostic Info:
I contacted someone at Dialogflow and this was their response.
Thank you for providing all the information. I have observed in your
code that you have used http requests instead of https. The service
must use HTTPS and the URL must be publicly accessible in order for
the fulfillment to function. Dialogflow does not support self-signed
SSL certs. For information on SSL setup, please refer to this :
https://developers.google.com/web/fundamentals/security/encrypt-in-transit/enable-https
We've had a somewhat different, but related, issue:
Internal Server Error when running an agent.
“status”: {
“code”: 500,
“errorType”: “internal_server_error”,
“errorDetails”: “Internal Server Error”
},
This error was not caused by any changes we introduced. We are using that agent in a dev version of an app and one morning it stopped working.
We tested by creating a .zip and restoring into a new agent. The new agent would work properly, but we would continue to get the 500 error on the agent hooked into our dev app. We submitted a help request and overnight the error got resolved. We suspect that DialogFlow team had to manually reboot the server or something similar.

Categories

Resources