BrowserSync / browser-sync

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

Proxy not working #1163

Open stoplion opened 8 years ago

stoplion commented 8 years ago

Issue details

Proxy never connects..

Starting a simple rack based web server running on port 9292, then try to proxy it

var browserSync = require('browser-sync').create();

gulp.task('browser-sync', function() {
  browserSync.init({
    proxy: 'http://localhost:9292',
    port: 4000
  });
});

$ gulp browser-sync pops open a new window but it just hangs..

Browsersync 2.14.0 Node v6.3.1 OS X 10.11.5

http://stackoverflow.com/questions/38755795/browser-sync-proxy-fails-to-connect

thymikee commented 8 years ago

Having the same issue with browser-sync@2.14. Can confirm it works as expected in browser-sync@2.13 so the new version must have introduced some regression (tested on Node v6.3.1 and v5.11.1).

thymikee commented 8 years ago

Ok, so I'm confused now. It indeed didn't work, but since I've removed whole node_modules and install v2.14.0 again, it works...

Tried to look for some of the dependencies that could get updated in the meantime I started the project, but haven't found any, most of them are locked down.

Just a shot, but maybe it has something to do with how NPM resolves dupes and how it depends on the order of installation.

Anyway, @stoplion, can you check if the same works for you?

1player commented 7 years ago

Same error here, tried versions 2.16, 2.14, 2.13, 2.11 and they all get stuck with a proxy configuration.

Running browser-sync with node_modules/.bin/browser-sync start --port 8000 --proxy localhost:8001

and yes, proxy on port 8001 is running and answering requests.

Removing node_modules and npm cache doesn't help.

GuyPaddock commented 7 years ago

For mine, I have to clean (i.e. delete the destination files) whenever the proxy starts to hang. I am not sure why deleting files makes a difference.

browniebroke commented 2 years ago

I have a simialr problem with the latest version of Browsersync and I noticed that it works when the host of the target is different 🤔

Before (not working):

browserSync.init({
  proxy: 'localhost:8000'
})

After (seems to work):

browserSync.init({
  proxy:  {
    target: '127.0.0.1:8000',
    proxyReq: [
      function(proxyReq, req) {
        // Assign proxy "host" header same as current request at Browsersync server
        proxyReq.setHeader('Host', req.headers.host)
      }
    ]
  },
})