curl trying to connect to other port than mentioned in url - node.js

im starting to build node app, and for this i am using curl. however, im facing an issue which i belive related to curl and my system configuration i just cant point to the exact issue.
at my nodeJS app i set the app to listen on port 3000, andwhenever i type in the command line :
curl -H "Content-Type: application/json" -X POST -d '{"url":"localhost:3000"}' http://localhost:3000/doAction
im getting the following error :
curl: (7) Failed to connect to localhost port 1080: Connection refused
it seems like curl is forcing connection to port 1080, although i was specifing port 3000, couldt find solution for this in the documentation.
if someone met this issue before and can assist it will be graet. tnx :)

I think your curl is trying to connect to proxy (default port 1080), why don't you run the command with --noproxy '*' i.e
curl --noproxy '*' -H "Content-Type: application/json" -X POST -d '{"url":"localhost:3000"}' http://localhost:3000/doAction

Related

docker container: curl: (7) Failed to connect to 172.17.0.1 port 4000: No route to host

I have graphql server running on the main machine on 4000 port
curl from the machine works well and I got what I expect:
curl -X POST -H "Content-Type: application/json" --data '{ "query": "{ me { _id } }" }' http://localhost:4000/graphq
when I do curl on container:
curl http://172.17.0.1
I got:
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.16.1</center>
</body>
</html>
It shows me that I can reach ngnix from container and it indicates for me that I can reach my machine from the container.
but when I curl form container:
curl -X POST -H "Content-Type: application/json" --data '{ "query": "{ me { _id } }" }' http://172.17.0.1:4000/graphql
I got:
curl: (7) Failed to connect to 172.17.0.1 port 4000: No route to host
I think you have to configure Nginx for public access because the docker uses a special network like it does have different network range you have to specify the network range in the Nginx server.
please refer the following link:
https://docs.nginx.com/nginx/admin-guide/security-controls/controlling-access-proxied-tcp/
https://www.cyberciti.biz/faq/linux-unix-nginx-access-control-howto/

Retrieve domain name from node in shared hosting

Hi have a NodeJs app in a shared hosting, where I'm trying to make API calls. Lets say my domain is example.com.
'http://localhost:' + global.PORT_SERVER + url + id
This works in local, because localhost is my machine; but in the server, as it's a shared hosting, the hostname is not my domain, but hl358.hostingexample.com.
$ hostname
$ hl358.hostingexample.com
Now with CURL from ssh, this works:
curl -i -H "Accept: application/json" "http://example.com:80/api/projects"
and this don't:
curl -i -H "Accept: application/json" "http://localhost:80/api/projects"
If I try to retrieve mydomain.com from node 'os' I still get hl318.hostingexample.com:
$ node
> const os = require('os')
> os.hostname()
'hl358.hostingexample.com'
No I'm a bit lost. Does anyone know how to retrieve actual domain with node?

curl always connects to a specific ip:port pair

I'm running into this scenario on one of our linux boxes.
$ curl 10.200.20.66:8087/ping
curl: (7) Failed to connect to 219.135.102.36 port 8118: Connection timed out
$ curl 114.114.114.114:80/x
curl: (7) Failed to connect to 219.135.102.36 port 8118: Connection timed out
As you can see, curl has always been trying to connect 219.135.102.36:8118.
I've tried using nc and telnet and both of them give correct results.
Finally I've turned to strace curl 10.200.20.66:8087/ping and here's output.
Can anybody help explain why this happened?
To be sure what is happening, turn on verbosity with -v switch:
$ http_proxy=1.2.3.4:8080 curl -v http://google.com
* About to connect() to proxy 1.2.3.4 port 8080 (#0)
* Trying 1.2.3.4...
* Connection timed out
* couldn't connect to host
* Closing connection #0
curl: (7) couldn't connect to host
In your case, I'd guess that Curl tries to use proxy. If that is the case, you should check the following:
http_proxy environment variable:
Check:
env | grep -i proxy
Curl configuration file ~/.curlrc (unlikely, it doesn't show in strace)
Proxy can be proxided on command line (-x or --proxy), so check if curl isn't aliased in your shell
Curl should be used with website, http,https,ftp.
example curl "http://www.google.com"
it provides the output in html format
Kindly check and try in correct format

Cannot Connect To Server - Migration Parse Server iOS

I am following this tutorial: https://www.raywenderlich.com/128313/parse-server-tutorial and I have successfully completed the steps to migrate my data to mLab as well as set up the parse-server.
I run this curl command
$ curl -X GET \
-H "X-Parse-Application-Id: <myAppId>" \
-H "Content-Type: application/json" \
-d '{}' \
http://localhost:1337/parse/classes/_User
And it returns me JSON of all my users. After this step, the tutorial says to run the app and post some data. However this is where I get stuck, I get the following error code when trying to login, [Error]: Could not connect to the server. (Code: 100, Version: 1.12.0). I configured my app key and my server url as instructed in the tutorial.
let configuration = ParseClientConfiguration {
$0.applicationId = "YOUR_APP_ID"
$0.clientKey = ""
$0.server = "http://localhost:1337/parse"
}
Parse.initializeWithConfiguration(configuration)
Set env var VERBOSE=1 before start your parse-server, and see what the difference from your curl request and ios sdk.
Once a request receive, parse-server will show the logs of the request. If you havn't see any log after your ios-app send request. Check your ios-app serverUrl is correct.
The serverUrl on your ios-app should not be localhost. Localhost means your device, and it not host the parse server. You should change it to the IP(except 127.0.0.1) or the domain name which host the parse server. If your phone and the server connect to same wifi, you can use 192.168.x.x(ifconfig) to connect.

how to get response from a remote server by using curl command through proxy?

Please give a simple syntax for making a curl command that will connect to the remote server through proxy......
curl -x my-proxy:8080 www.bbc.co.uk
Try here for more details: http://curl.haxx.se/docs/manual.html

Resources