BrowserSync / browser-sync

Keep multiple browsers & devices in sync when building websites. https://browsersync.io
https://discord.gg/2d2xUThp
Apache License 2.0
12.19k stars 757 forks source link

Proxy config doesn't work with "localhost" it only works with "127.0.0.1" #1979

Open NathanBowers opened 2 years ago

NathanBowers commented 2 years ago

Issue details

Documentation says that proxy: 'localhost:4567' will work. In the past it did work but as of now localhost doesn't work and I have to use proxy: '120.0.0.1:4567' instead. I'm using Ruby Middleman static site generator with gulp to build static assets and startup BrowserSync.

If I gulp config proxy: 'localhost:4567' the BrowserSync UI server starts ok but trying to browse to localhost:7000 hangs as if no server is started there. I can browse the Middleman server at localhost:4567fine, it's just not being proxied.

I don't mind using an IP address instead of localhost, but the documentation all says that localhost works and this was a breaking change after I recently upgraded all my node packages, gems, ruby, and macOS.

Steps to reproduce/test case

My simplified gulp file init:

  browsersync.init({
    proxy: "localhost:4567",  // <-- "localhost" doesn't work. When I change it to 127.0.0.1:4567 it does work
    port: 7000,                     
     ui: {
       port: 7001               
       }
  });

The full codebase is at https://github.com/NathanBowers/mm-template if that helps.

Please specify which version of Browsersync, node and npm you're running

Affected platforms

Browsersync use-case

If CLI, please paste the entire command below

{cli command here}

for all other use-cases, (gulp, grunt etc), please show us exactly how you're using Browsersync

Here's the init from my gulp file:

function browserSync(done) {
  browsersync.init({
    notify: true,                   
    ghostMode: true,                
    open: true,                     
    reloadOnRestart: true,
    proxy: "localhost:4567",  // <-- "localhost" doesn't work. When I change it to 127.0.0.1:4567 it does work
    port: 7000,                     
     ui: {
       port: 7001               
       }
  });
  done();
}

The full codebase is at https://github.com/NathanBowers/mm-template if that helps.

homestar9 commented 1 year ago

Can confirm this issue exists on my machine as well. The docs should be updated if you can no longer use localhost and instead must use 127.0.0.1 instead.

paulmsmith commented 1 year ago

I've bumped into this issue. I can confirm not using not using localhost but instead using 127.0.0.1 also worked for me.

Is this a browsersync issue? I thought it might be something related to a new router I've added with DNS rebind protection enabled or perhaps an update to MacOS?

RileySeaburg commented 12 months ago

This is still an issue.