Access oData in nodejs - node.js

I am getting an error as the below
Error: getaddrinfo ENOTFOUND sap host
i tried to connect using request module and used the method get. i used base64 encoded authorization parameter were also passed to the options but still getting the same error.

Ciao, interesting error. According to npm you are correctly using client.get request. I found this discussion. They talking about hhtp.get so it's not exaclty your problem BUT I think the error is the same.
In brief:
This is the first suggestion:
getaddrinfo is by definition a DNS issue. Does dig host or nslookup host work? Does dns.lookup(host, console.log) work?
The second one is:
Setting the family to 4 is working.
var options = {
host: '_host_',
family: 4,
port: 80,
path: '/'
};
Try to put family: 4 in your args. This could solve your problem.

Related

RPC Error - valid string HTTPs rpc in Metamask

In my project, I tried to connect with metamask on Ganache. But I got the error like the following.
inpage.js:1 MetaMask - RPC Error: Expected an array with at least one valid string HTTPS url 'rpcUrls', Received:
http://127.0.0.1:7545/
code: -32602
message: "Expected an array with at least one valid string HTTPS url 'rpcUrls', Received...
Please let me know how can fix it.
I'll be assuming your code looks like the following:
await ethereum.request({
method: 'wallet_addEthereumChain',
params: [
{
chainId: '0x539',
chainName: 'Gananche',
rpcUrls: 'http://127.0.0.1:7545/'
}
]
});
The rpcUrls value has to be an array, but from your error message it looks like you're passing a string. To fix this, make the value an array as follows:
await ethereum.request({
method: 'wallet_addEthereumChain',
params: [
{
chainId: '0x539',
chainName: 'Gananche',
rpcUrls: ['http://127.0.0.1:7545/'] // Is now an array
}
]
});
you can install localtunnel to tunneling to local HTTPS server
npm install -g localtunnel
and after use the command line interface to request a tunnel to your local server:
lt --port 7545
An url will be created (ex: https://wise-mule-dig-195-131-122-13.loca.lt/)
Open the url created and click on the button "Click to continue"
After you can used this new url instead of http://127.0.0.1:7545/
I have had the same issue and I believe that it is because of the unsafe http url, since it allowed me to pass on the same parameters changing http to https.
So possibly localtunnel might work for you as Patrikoko said?
Another possibility that keeps everything local could be:
https://www.npmjs.com/package/local-ssl-proxy
This serves it with a self signed certificate
In the github readme is says you can serve it with your own trusted certificate as well:
https://github.com/cameronhunter/local-ssl-proxy#readme
local-ssl-proxy --key localhost-key.pem --cert localhost.pem --source 9001 --target 9000

Node - P2P Webrtc-Star

I am following a tutorial on how to create a colabrative document. The github is below. It uses ipfs for the P2P aspect.
https://github.com/ipfs-shipyard/shared-editing-demo
I am getting the following error:
Uncaught Error: no protocol with name: libp2p-webrtc-star
I have searched and found possible solutions e.g. changing the config found in the link below but it has not worked:
https://github.com/ipfs/js-ipfs/issues/1029
config: { // overload the default config
Addresses: {
Swarm: [
"/dns4/star-signal.cloud.ipfs.team/wss/p2p-webrtc-star"
],
API: '',
Gateway: ''
},
}
})
The above does not work as I still get the same error. There was a mention (on the github) of swarm having both the old and the new config together and that is why the error is being thrown. However, I am unsure how to resolve this.
i had that with 0.41.0 version. also try to use /dns4/ws-star.discovery.libp2p.io/tcp/443/wss/p2p-websocket-star
switch back to 0.40.0 worked for me

Node.js Net.Socket() to connect to net.tcp web service

So I have a web service running on port 7001 over TCP on:
net.tcp://www.myurl.com:7001/my/webservice
and I want to connect to it using net.Socket:
client.connect(7001, 'myurl.mine.com/my/webservice', function () {
console.log('Connected');
client.write(msg);
});
When i do the above, it gives an exception:
Error: getaddrinfo ENOTFOUND <<my url>>
at GetAddrInfoReqWrap.onLookup [as oncomplete]
when i try connect to it without the /my/webservice, it connects fine and doesnt give an error at the client.connect() stage, but obviously cant find that endpoint so it gives another error when i try to do the client.write()
Any one any idea how to use net.Socket against a web service with a url that isnt just myurl.com:7001 but actually contains a route like myurl.com:7001/my/webservice?
According to node.js docs the version of the method you are using expects only a hostname for a second argument. You are providing hostname + path
In your case I would recommend using a more generalized version of net.connect which accepts an object with parameters. So your code will look something like this:
client.connect({
host: 'myurl.mine.com',
port: 7001,
path: '/my/webservice'
},
function () {
console.log('Connected');
client.write(msg);
}
);

Issue with HTTP request using node through TOR

I am relatively new to both node and TOR. I'm trying to send a request using a node application through TOR. Ive set up a basic app using socks5-HTTP-client. Also, TOR is installed (sudo port install tor) and I ran the server using tor..
Executing the app, node gives me the following error
Error: SOCKS connection failed. General SOCKS server failure.
at Socket.<anonymous> (/Users/MyName/node_modules/socks5-client/lib/Socket.js:199:12)
at Socket.g (events.js:260:16)
at emitOne (events.js:77:13)
at Socket.emit (events.js:169:7)
at readableAddChunk (_stream_readable.js:146:16)
at Socket.Readable.push (_stream_readable.js:110:10)
at TCP.onread (net.js:523:20)
The TOR server reports the following to me:
[warn] Rejecting SOCKS request for anonymous connection to private address [scrubbed].
The topic I found here does not seem to apply to this case. Also, this earlier article does not answer my question. Neither can I find any difference between the example given by the developer of the socks5 module and my case.
I am unsure whether this is an issue with my configuration in node or my TOR configuration.
Below is the JS code
var shttp = require('socks5-http-client');
var config =
{ url: 'http://whatismyipaddress.com/', // I'd like to see a different IP on every request, that should be the end result, correct?
socksHost: '127.0.0.1',
socksPort: 9050
}
shttp.get(config, function(res) {
res.setEncoding('utf8');
res.on('readable', function() {
console.log(res.read());
});
});
Also, in my torrc.sample configuration file, I made sure the following is set up:
SOCKSPort 127.0.0.1:9050
Also, my SOCKSPolicy is set up as follows:
SOCKSPolicy accept 192.168.0.0/16
SOCKSPolicy accept6 FC00::/7
SOCKSPolicy reject *
At the time of trying, my internal IP address was 192.168.0.11, seems fine to me.
Any help would be appreciated!
You are getting that error because the URL isn't getting passed to the request properly so it is trying to issue a SOCKS request to localhost instead of the site you want to visit.
URLs are parsed using url.parse.
Try changing your code to:
var shttp = require('socks5-http-client');
var url = require('url');
var config = url.parse('http://whatismyipaddress.com/');
config.socksHost = '127.0.0.1';
config.socksPort = 9050;
shttp.get(config, function(res) {
res.setEncoding('utf8');
res.on('readable', function() {
console.log(res.read());
});
});
Also, it appears whatismyipaddress.com might be blocking Tor as I don't get a response back from them. Try ipchicken.com or some other site. You may need to set a User-Agent header to get the former site to reply, but this code change does work.

rest call from node fails

I am building a node.js/express app which makes remote calls to other internal web application (ASP.NET WEB API) to consume json from it. We are in a corporate network. Here is the strange issue.
On my Mac OSX (Mavericks), I can curl from shell and get json from http://our_internal_host:9991/connections. I can also type this URL and see the JSON response from the browser.
When I run this express app locally and request the route which makes the remote call, I see this error on the console. The route handler logs this message below and browser hangs.
{ [Error: connect ECONNREFUSED]
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect' }
Node process cannot make a connection to that address. I also have a Windows 7 machine at work and I do not encounter this issue on my Windows 7 machine. When I run the same node app on Windows 7, I don't have any issues.
I am not sure how to troubleshoot the issue...
PS: A colleague of mine who has the same setup doesn't have this issue. We compared DNS configs but our setup looks to be same.
Any pointers to troubleshoot this issue is much appreciated. I know this is environment specific issue but not sure where to start.
Thanks
EDIT #1
Route handler making the remote call which logs the error above...
var http = require('http');
var options = {
host: 'our_internal_host',
port: 9991,
path: '/analytics'
};
http.get(options, function(res) {
// removed response code
console.log(res);
}).on('error', function(e) {
console.log(e);
});
It turns out my Mac's IP was on a different subnet than other machines.

Resources