Resolving polling URL
See original GitHub issueHi all, My gulp task is setup with the bare-bones browser-sync instance within a WordPress site:
gulp.task 'browser-sync', -> browserSync() return
I’m not able to use the proxy option due to this being a multisite install – so I went the route of adding the following right before </body>
:
/**
* Add inline browsersync function for live reloads locally only to wp_footer()
* @return void
*/
function bt_browsersync() { ?>
<script type='text/javascript' id="__bs_script__">//<![CDATA[
document.write("<script async src='http://HOST:3000/browser-sync/browser-sync-client.2.7.12.js'><\/script>".replace("HOST", location.hostname));
//]]></script>
<?php }
add_action('wp_footer', 'bt_browsersync', 9999);
I’m not able to use HOST
as the variable here though, because the file is not available going through http://wpsite.dev:3000/browser-sync/browser-sync-client.2.7.12.js
and only works by going to local:3000/browser-sync/browser-sync-client.2.7.12.js
, so I changed the above to the following:
/**
* Add inline browsersync function for live reloads locally only to wp_footer()
* @return void
*/
function bt_browsersync() { ?>
<script type='text/javascript' id="__bs_script__">//<![CDATA[
document.write("<script async src='http://localhost:3000/browser-sync/browser-sync-client.2.7.12.js'><\/script>");
//]]></script>
<?php }
add_action('wp_footer', 'bt_browsersync', 9999);
The problem now is that when browsersync is polling the page, it is using the site URL to reference the GET request, so I get these console errors:
http://wpsite.dev:3000/browser-sync/socket.io/?EIO=3&transport=polling&t=1434574564882-43 net::ERR_CONNECTION_REFUSED
How can I set those URLs to use localhost
in this case as well? I looked into scriptPath
, but that did not change anything. Thanks!
Note
I am running the install through Vagrant.
Issue Analytics
- State:
- Created 8 years ago
- Comments:7 (3 by maintainers)
Top GitHub Comments
Please see https://github.com/BrowserSync/browser-sync/issues/690
tl;dr
You can alter the domain for websockets via
http://www.browsersync.io/docs/options/#option-socket