-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
browserSync requires cumbersome work-arounds to function #6
Comments
Currently I issue the following command at the command line --
And here is my docker-compose.yml
I also need to force my proxy in the browserSync config to
Additionally I have to add an entry in my /etc/hosts file --
While this works, it is an awful work-around with the following problems:
I am sure this can be cleaned up to "just-work". However, I am too new to docker to solve this issue on my own just yet. Thought this might be a good place to start the discussion as I have a feeling you and I are like minded in wanting to do as little project-specific of environment-specific configuration as possible along with not having to remember to run a bunch of commands to get something to work just because of docker. |
@bretmette I'm not familiar with Since I'm not familiar with this setup, can you put together a reduced test case I can use to reproduce the issue? I don't think I need anything around the db, or the watcher processes, but if you could explain what you're doing with the |
Here's what did work for me (I'm sure I'm missing pieces of the puzzle). I used this package.js: {
"name": "test-project",
"version": "0.0.1",
"devDependencies": {
"browser-sync": "^2.16.0",
"grunt": "~0.4.5",
"grunt-contrib-jshint": "^1.0.0",
"gulp": "~3.9.1",
"gulp-jshint": "~2.0.1",
"jshint": "~2.9.2"
}
} I reduced the gulpfile to var gulp = require('gulp');
var browserSync = require('browser-sync');
gulp.task('watch', function() {
browserSync.init({
files: ['{lib,templates}/**/*.php', '*.php'],
open: false,
snippetOptions: {
whitelist: ['/wp-admin/admin-ajax.php'],
blacklist: ['/wp-admin/**']
}
});
}); And I executed it with
Navigating to that host (or |
@mkenney Browsersync is amazing, it really speeds up development (not as much as it could due to the docker OS X filesystem performance issues...). The ability to access the Browsersync UI does not tell the full story. The issue is that Browsersync itself is a proxy (among other things). The UI is run on the gulp container and accessed via port 3001, no problem there. But when you go to access the site (default on port 3000) Browsersync doesn't know how to handle the request. Say you have http://localhost:3000/ when you hit that you first are sent to the Browsersync container, Browsersync will then attempt to access http://localhost:80/ rewrite some URLs and send the data back on port 3000 to the browser. The problem is your http server container is not the same as the one running gulp and Browsersync. So when Browsersync tries to access http://localhost:80/ it gets blackholed (since the gulp container is not serving any content on port 80, the httpd container is). So my solution is to stitch them together using the "local.dev" hostname via this section of the docker-compose.yml.
This adds an entry in the frontend-dev container's /etc/hosts file for local.dev and points it to the nginx (http server) container's IP. So now when I hit http://local.dev:3000/ the proxy path is
vs using http://localhost:3000/
The reason the Browsersync UI works without a problem on port 3001 is because Browsersync doesn't proxy the UI, it serves it from it's own container so it works without an issue. It's when Browsersync tries to access localhost:80 that it runs into a dead end. Let me know if that makes sense. So for now my bad workaround is in this comment. |
@bretmette Ahh, ok, that does makes sense. I'm not sure there's a better way to do that without implementing some kind of DNS resolution that your proxy can take advantage of, I haven't done that on a Mac in years but it's relatively straightforward these days. I do most of my development on remote boxes with wildcard DNS resolution which makes connecting that stuff together a bit easier. |
@bretmette So I had a thought. I think you can add If you give that a try, let me know how it works out. |
@mkenney my setup has become slightly more complex now. I am running a reverse-proxy using nginx so that I can run multiple apps at once. So I have a container I start outside of the app's docker-compose called What I do now is setup the frontend-dev container to use the same hostname as what is specified in the
Where There is more to it, using external networks, etc so that everything can talk to each other, but it seems to be working. I don't think I could run more than one frontend container at once, but that shouldn't be an issue. I could always switch up the port so each one has a unique port if I need to do that. |
@bretmette that proxy is awesome, I use it all the time. Again, I'm not totally sure how your setup, but I'm reasonably sure you could setup as many projects as you want. I use the proxy to run 12 different hosts on my dev server at the moment. They're all on random docker ports but I access them all on port 80 through the proxy. I'm going to go ahead and close this, thanks for letting me know! |
@mkenney yes, I have been setting up all my projects to use the reverse proxy and it kicks ass. I have a container that is set to I think the bottom line is BrowserSync will require a little bit of additional setup and depending on the individual's workflow they will need to configure things accordingly. The main reason it does not work "out-of-the-box" is because the docker-npm container does not expose ports 3000 & 3001 to the host (which are the default for BrowserSync). Even if it did, there would be multiple problems with routing associated with it, (i.e. localhost is not the same on the host as it is in the container so some sort of middleware is needed to fix the routing). I think using a custom binary to run I believe to make this work docker-npm would have to detect if BrowserSync is being used in gulp or grunt and then modify the container at run-time to expose the correct ports to the host. Additionally it would have to setup custom routing in the docker network associated with docker-npm. That seems out of scope for this project. |
@bretmette any chance you could post your current Docker-Compose file that makes use of the jwilder nginx proxy? I love that thing but I am trying to get browsersync to work and I think I am attempting to solve the same problems you solved to get your setup rolling. I am working with ghost.org instead of wordpress but essentially everything else is the same. I assume I could make things work using your initial docker-compose / gulp setup but it seems like you have evolved since then! Thanks in advance! |
@bretmette and others I would love to see a solution to this problem. I am trying to set up a very simple environment that my students can use on both mac and windows. I think setting a hostname in /etc/hosts is beyond their skill level. If someone else has figured out a solution I'd be very pleased to hear it. |
@titaniumbones I don't know that there is a self-contained solution that doesn't require configuring hosts or something more complicated. But, I don't really understand the BrowserSync workflow. If someone would like to put together a small demo project with a note on what to expect when running it I'd be happy to look closer for a way to try and make it work. |
I thought I would create an issue here to discuss a better workaround / solution for browserSync. Let me know if you are interested in discussing that. I can move the issue to my own fork if it is not something you want to pursue with me.
Currently when running
gulp watch
which triggers browserSync the connection is null-routed. I have a really ugly work around that I think we can improve upon.The text was updated successfully, but these errors were encountered: