ddev-browsersync icon indicating copy to clipboard operation
ddev-browsersync copied to clipboard

Support multi-domain setups and create a proxy middleware for each domain

Open mmunz opened this issue 2 years ago • 9 comments

mmunz avatar Jan 26 '23 17:01 mmunz

@mmunz Thanks for PR.

Could you some steps here I can follow so I can test it?

tyler36 avatar Jan 26 '23 23:01 tyler36

@tyler36 i created a ddev test setup here: https://github.com/mmunz/browsersynctest/tree/multiple-domain-support

It is a ddev setup with an additional hostname and two docroots.

To test it do:

  • checkout the test project (multiple-domain-support)
  • ddev get ddev/browsersync to get the original version
  • ddev start
  • ddev browsersync
  • open https://browsersynctest.ddev.site:3000 and https://browsersynctest2.ddev.site:3000/ - they both show the same text because the proxy uses the first hostname (browsersynctest.ddev.site)
  • ddev stop
  • ddev get https://github.com/mmunz/ddev-browsersync/tarball/support-multidomain-setups
  • ddev start
  • ddev browsersync
  • https://browsersynctest2.ddev.site:3000/ should now show different text and test in red. (If text is not red: this is probably the browser cache)

mmunz avatar Jan 27 '23 10:01 mmunz

@mmunz

I had a look at the PR today. Using this ddev get https://github.com/mmunz/ddev-browsersync/tarball/support-multidomain-setups

After running it, I opened https://browsersynctest.ddev.site:3000/ & https://browsersynctest2.ddev.site:3000/;

Changes made to browsersynctest1/index.html reload both pages. Changes made to browsersynctest2/index.html triggers nothing.

Is that the expected behavior?

tyler36 avatar Feb 01 '23 04:02 tyler36

@mandrasch would this have helper for your use case (#27) ?

tyler36 avatar Feb 01 '23 04:02 tyler36

@tyler36 i have to look deeper into this, but i suspect this is same strange caching issue (browser cache or even the http-proxy-middleware).

mmunz avatar Feb 14 '23 15:02 mmunz

@mandrasch would this have helper for your use case (#27) ?

Can't really say. While reading through the steps provided by @mmunz I just noticed that I never used the ddev browsersync command...

I just installed ddev-browsersync to open up the port via the docker-compose file...In LaravelMix browsersync was controlled by the package itself (https://laravel-mix.com/docs/6.0/browsersync), see also my answer https://github.com/ddev/ddev-browsersync/issues/27#issuecomment-1322656310. Guess my issue was more a docs-related one to LaravelMix integration.

Much success solving this!

mandrasch avatar Feb 14 '23 22:02 mandrasch

@tyler36 The problem was, that in the demo project the public folder was not properly watched. I've updated https://github.com/mmunz/browsersynctest/tree/multiple-domain-support to watch for files in public in browser-sync.js now.

mmunz avatar Feb 15 '23 14:02 mmunz

Sorry for the delayed response. Is this still valid and a "good" approach?

tyler36 avatar Feb 01 '24 03:02 tyler36

@tyler36 well, it's the best solution for the problem i came up with. I'm also using it in my own multidomain projects. The downside is that it adds a bit of complexity.

But i'd love to hear from others, if they use this approach and if it works, or if there exist better solutions.

mmunz avatar Mar 29 '24 06:03 mmunz

Thank you for your work on this.

Due to lack of demand from the community, I'm going to close this for now.

I'm happy to re-open if there's a push in demand or if you feel strongly.

tyler36 avatar Nov 22 '24 03:11 tyler36