12

Can someone tell me why my proxy URL isn't working with BrowserSync and Gulp? Instead, it just keeps using http://localhost:3000 as the dev URL.

gulp.task('watch', ['bs'], function() { gulp.watch('scss/*.scss', ['scss', browserSync.reload]); }); gulp.task('bs', function() { browserSync.init(['css/style1.css', 'css/style2.css'], { proxy: 'dev.site.com' }); }); gulp.task('default', ['scss', 'watch']); 
4
  • Your syntax looks off compared to docs -> browsersync.io/docs/api/#api-browserSync Commented Feb 17, 2015 at 17:31
  • Do you mean that it keeps opening the localhost:3000 url? Commented Feb 17, 2015 at 17:33
  • 3
    Correct. It just completely ignores the dev URL I'm trying to use. (that matches my local WordPress site) Commented Feb 17, 2015 at 17:36
  • i've configurated some custom urls to my vhost and after some updates (imho) some internal configuration is changed. so now i set the port as configured on my vhost (port 80). now is working fine. hope help Commented Oct 31, 2018 at 10:13

5 Answers 5

6

I had the same problem and did the following to stop browser-sync from using the default adress/port:

gulp.task('bs', function () { browserSync.init(null, { proxy: 'localhost:8080', // 'dev.site.com' in your example port: 5000 }); }); 

This worked for me and change the browser-scyn adress to localhost:5000

Sign up to request clarification or add additional context in comments.

1 Comment

Hey, i m using like this .browserSync({ files: [ 'public/**/*.js', 'public/**/*.css', './resources/**/*.php', './resources/**/*.less' ], proxy: '0.0.0.0:8181', port: 8282, ghostMode: { scroll: true } }) not working for me. but proxy port is working fine
1
//Finally what worked for me: gulp.task("serve", () => { browserSync.init(null, { proxy: "127.0.0.1:8000/", open: true, }); gulp.watch(["src/templates/**/**/*.html"], gulp.series("html")); }); gulp.task("default", gulp.series("html", "serve")); 

Comments

0

You need to use the port at the end of the proxy URL. The default is 3000, but you can specify one in the config. If you don't add the port at the end of the url, BrowserSync will not reload the page. This is what worked for me.

function server() { browserSync.init({ proxy: 'dev.site.com', //alias port: 8080, //<-- changed default port (default:3000); open: false //<-- set false to prevent opening browser }); } 

So in your browser you will visit: http://dev.site.com:8080

Comments

-2

To solve this issue when I was trouble in a similar scenario, I had to include the port option (which @maximilian mentioned in his answer) , and also the files option was needed as well.

gulp.task('bs', function() { browserSync.init({ proxy: 'dev.site.com', port: 4040, files: ['*.html', '**/*.css', '**.*.js'] }); }); 

Comments

-6

I think it works as expected.

Proxy an EXISTING vhost. BrowserSync will wrap your vhost with a proxy URL to view your site.

http://www.browsersync.io/docs/options/#option-proxy

3 Comments

I don't understand this answer. I'm getting the same problem as Cofey. Please can you elaborate at all? I need it to open test.dev rather than localhost:3000 :(
Can you elaborate on this? Why would anyone wrap the existing vhost instead of just accessing localhost:3000 either way?
When the stuff they need to access is not in localhost:3000?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.