0
votes

Hello i am having trouble with vagrant setup. So i am trying to ping serverless API which runs on http://localhost:3000/ (and it's outside vagrant project).

Right now my vagrant project runs on https://localhost:4443/.

Overall trying to CURL request from vagrant project to another serverless project.

  1. Tried to use http://localhost:3000/ in CURL request but getting Failed to connect to localhost port 3000: Connection refused

  2. Tried to use VM ip 10.0.2.15 address same

  3. Tried to do port forwarding in vagrantfile config.vm.network :forwarded_port, guest: 3000, host: 3000 and use machine IP address 192.168.0.16, getting empty response from server, when i try to do telnet 192.168.0.16 3000 getting

    Trying 192.168.0.16... Connected to 192.168.0.16. Escape character is '^]'. Connection closed by foreign host.

Any idea what to try?

2

2 Answers

0
votes

I had to use VM IP address something like curl -X GET http://10.0.2.2:3000

0
votes

These errors may be caused due to follow reasons, ensure the following steps are followed. To connect the local host with the local virtual machine(host). Here, I'am connecting http://localhost:3001/ to the http://abc.test Steps to be followed:

1.We have to allow CORS, placing Access-Control-Allow-Origin: in header of request may not work. Install a google extension which enables a CORS request.*

2.Make sure the credentials you provide in the request are valid.

3.Make sure the vagrant has been provisioned. Try vagrant up --provision this make the localhost connect to db of the homestead.

  1. Try changing the content type of the header. header:{ 'Content-Type' : 'application/x-www-form-urlencoded; charset=UTF-8;application/json' } this point is very important.