usebruno / bruno

Opensource IDE For Exploring and Testing Api's (lightweight alternative to postman/insomnia)
https://www.usebruno.com/
MIT License
26.15k stars 1.2k forks source link

Localhost #124

Closed rfoel closed 10 months ago

rfoel commented 1 year ago

Does bruno work on localhost? I keep getting the following error when I send a request:

Error invoking remote method 'send-http-request': Error: connect ECONNREFUSED 127.0.0.1:3000

PS: My local server is running, I can call it with Insomnia, but not with bruno.

I'm on a Mac M1.

Fancman commented 10 months ago

I am running website on apache2 in WSL2 WIndows 10. In hosts file I set custom local URLs for webapp and now when I am requesting API endpoints it is returning error which is getting everyone in thread. I cant fix it with ::1 in URL because I am running multiple websites in apache under 80 port. In Insomnia it works fine.

::1               www.oplatisa.sk.local
127.0.0.1         www.oplatisa.sk.local
::1               oplatisa.sk.local
127.0.0.1         oplatisa.sk.local

@Fancman just saw that you had the domains in your hosts file, so it should have worked. I will try to reproduce the issue you had with *.local, could you share exactly how it's setup on your machine, for example :

  • wsl2 run an http server on test.local on port 8080, do you bind ::1 explicitly?
  • Bruno run on windows, but can't reach test.local
  • hosts file was modified on windows system32/driver/etc/hosts or is it the host file of wsl2 in /etc/hosts?

Thanks a lot!

On WSL I installed apache2, created and enabled config for website which listens on 80 port:

/etc/apache2/sites-available/oplatisa.sk.conf

<VirtualHost *:80>
        ServerName www.oplatisa.sk.local
        ServerAlias oplatisa.sk.local
        DocumentRoot /var/www/oplatisa.sk/public
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        # To make URL segments work
        <Directory /var/www/oplatisa.sk/public>
                Options Indexes FollowSymLinks
                AllowOverride All
                Require all granted
        </Directory>
</VirtualHost>

Then I modified C:\Windows\System32\drivers\etc\hosts and it seems that it automatically got replicated into /etc/hosts because it contains same addresses.

C:\Windows\System32\drivers\etc\hosts

::1               www.oplatisa.sk.local
127.0.0.1         www.oplatisa.sk.local
::1               oplatisa.sk.local
127.0.0.1         oplatisa.sk.local

::1               www.oplatisa.sk.localhost
127.0.0.1         www.oplatisa.sk.localhost
::1               oplatisa.sk.localhost
127.0.0.1         oplatisa.sk.localhost

\etc\hosts

# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl># [network]
# generateHosts = false
127.0.0.1       localhost
127.0.1.1       nb-figura.      nb-figura

::1     www.oplatisa.sk.local
127.0.0.1       www.oplatisa.sk.local
::1     oplatisa.sk.local
127.0.0.1       oplatisa.sk.local
::1     www.oplatisa.sk.localhost
127.0.0.1       www.oplatisa.sk.localhost
::1     oplatisa.sk.localhost
127.0.0.1       oplatisa.sk.localhost

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix

Then I tried to make requests from Bruno which is installed on Windows 11 and couldnt access it. Before that I had website running in WSL under localhost and when I tried to access it with Bruno from Windows it worked (GET 127.0.0.1). Problems started when I changed website address to oplatisa.sk.local

BrandonGillis commented 10 months ago

Thanks for the detailed answer, that will help a lot to reproduce the issue!

emflomed17 commented 8 months ago

I believe for MacOS users this is still an issue right?

I'm still getting the: "Error invoking remote method 'send-http-request': Error: connect ECONNREFUSED 127.0.0.1:3000"

Request example: http://localhost:3000/dev/poc/1a9c4c0f-0ee2-4155-9848-1d047382c5a7

It is a serverless framework project.

My Bruno version is 1.7.1

I have: M2 Chip Sonoma 14.2.1

Kind of sad because I really wanted to give it a shot to Bruno.

anitachan commented 8 months ago

I have the same issue. I'm using 1.6.1. I have an intel mac with Sonoma 14.3. In insomnia works well but bruno doesn't. This is my error! Error invoking remote method 'send-http-request': Error: connect ECONNREFUSED ::1:8080

muffe commented 7 months ago

Same issue here

macOS: 14.3.1 Bruno: 1.10.0

Trying to run a pre request script

const fetch = require("node-fetch");
const body = {
  email: "{{username}}",
  password: "{{password}}"
};

const response = await fetch('http:/127.0.0.1:3000/api/users/login', {
    method: 'post',
    body: JSON.stringify(body),
    headers: {'Content-Type': 'application/json'}
});
const data = await response.json();

bru.setVar("ACCESS_TOKEN", data.accessToken);

The error given is

Error invoking remote method 'send-http-request': 
FetchError: request to http://127.0.0.1:3000/api/users/login failed, reason: connect ECONNREFUSED 127.0.0.1:3000

The application is running at 127.0.0.1:300. If I run a "normal" request in bruno against the endpoint it works, but as soon as the context is the pre request script the above error occurs.

druxton-consid commented 7 months ago

Can confirm this is still an issue unfortunately

jquinc30 commented 7 months ago

For @druxton-consid and the ones who continue to experiment the issue, I found 2 workarounds for a teammate that both works for us but I really prefer the second one:

  1. In the URL, replace localhost by your ip address [for example, you can find it thanks to the output of the command ifconfig]
    • Example: http://localhost:3000/xyz should be replaced by http://yourIP:3000/xyz. So if yourIP is 10.123.124.125, it should be http://10.123.124.125:3000/xyz
    • NB: with this solution, your will need to change the URL each time your IP address updates. Check the second point for a more robust/long term solution.
  2. Update your OS hosts file (/private/etc/hosts on a mac) and create a fake local domain name to trick Bruno.
    • Add 127.0.0.1 bruno.local [here bruno.local is arbitrary and can be replaced] (cf line 12 in the below screenshot) image
    • Replace localhost by this domain in URL in Bruno.
    • Example: http://localhost:3000/xyz should be replaced by http://bruno.local:3000/xyz.
mig8447 commented 6 months ago

This is still an issue in macOS for me, I managed to fix it by using http://127.0.0.1 instead of http://localhost but this is still an issue with bruno (even the CLI) preferring IPV6

For the CLI you can use the following:

NODE_OPTIONS=--dns-result-order=ipv4first npx -y --package @usebruno/cli bru run

This will make the Bruno CLI to use ipv4 name resolution first

douglasmiranda commented 6 months ago

Bruno 1.12.3 System: Pop!_OS 22.04 Using Bruno AppImage version

Basically same thing happening with me.

Trying to access http API running in container. Ran into the same problems of localhost vs 127.0.0.1 and in some cases my request went through but I've noticed my request with a json body just wont go through.

Doing the same exact comand with cURL or using httpie works just fine.

For reference, I tried the example in this API specifically https://docs.browserless.io/HTTP-APIs/pdf

trevorrobertsjr commented 3 months ago

Bruno 1.19.0 CPU: M3 Pro OS: macOS 14.5

I am unable to access my flask[async] server via http://localhost. It works with http://127.0.0.1. It works fine with curl If I use the standard wsgi flask server or with gunicorn, http://localhost works.

berain-uvic commented 1 month ago

On Windows 11 I was having the same issue, uninstalling and reinstalling solved the isssue.