question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Resolving polling URL

See original GitHub issue

Hi 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:closed
  • Created 8 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
shakyShanecommented, Jun 28, 2015

Please see https://github.com/BrowserSync/browser-sync/issues/690

tl;dr

socket: {
    domain: "localhost:3000"
}
2reactions
shakyShanecommented, Jun 26, 2015

You can alter the domain for websockets via


// This will result in something like this in
// the socket connector code
// browserSync.io('localhost:3003/browser-sync')
socket: {
    namespace: function (namespace) {
        return "localhost:3003" + namespace;
    }
}

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Polling URL synchronously - javascript - Stack Overflow
I'm looking to make a function which polls a certain URL synchronously (i.e. send one request, wait for ...
Read more >
The polling url does not start with https despite the login url ...
I found a solution after digging a lot on internet. Following changes solve the problem. 'trusted_domains' => array ( 0 => 'domain.ltd', ),...
Read more >
Implementing HTTP Polling - Abhinav Pandey
This is how polling works in a nutshell: The client makes a request to the server just like a simple HTTP request.
Read more >
Long polling - The Modern JavaScript Tutorial
The simplest way to get new information from the server is periodic polling. That is, regular requests to the server: “Hello, I'm here,...
Read more >
Recommended configuration for HTTP URL monitoring and ...
Recommended configuration for HTTP URL monitoring and the SAM Polling Agent ... To be fair joedissmeyer​ I'm glad to hear that resolved your...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found