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.

When using the proxy option and loading browser-sync manually via inline script tag it would be nice to have the possibility to check if the server on port 3000 is running, like this:

var url = '//' + location.hostname + ':3000/browser-sync-client.js',
    xhr = new XMLHttpRequest();

xhr.onreadystatechange = function() {
    if(xhr.readyState == 4 && xhr.status == 200) {
        document.write(('<script async="async" src="' + url + '"><\/script>'));
    }
};

xhr.open('HEAD', url, true);
xhr.send();

The problem is that sending the head request is not allowed, because the browser treats the request to the server on port 3000 as a cross-domain request. It would be nice to have an option to configure CORS headers for the browser-sync server.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:14 (3 by maintainers)

github_iconTop GitHub Comments

11reactions
shakyShanecommented, Sep 29, 2016

@bclinkinbeard @TeodorKolev also, since 2.16.0 this is supported via the cors option.

const bs = require('browser-sync').create();

bs.init({
    server: './app',
    cors: true
});
6reactions
bclinkinbeardcommented, Sep 29, 2016

@TeodorKolev you need to add this to your BS config:

middleware: function (req, res, next) {
  res.setHeader('Access-Control-Allow-Origin', '*');
  next();
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Cross-Origin Resource Sharing (CORS) - MDN Web Docs
Cross-Origin Resource Sharing (CORS) is an HTTP-header based mechanism that allows a server to indicate any origins (domain, scheme, ...
Read more >
CORS Enabled - W3C Wiki
Open Internet Information Service (IIS) Manager · Right click the site you want to enable CORS for and go to Properties · Change...
Read more >
Express cors middleware
CORS is a node.js package for providing a Connect/Express middleware that can be used to enable CORS with various options.
Read more >
Enable Cross-Origin Requests (CORS) in ASP.NET Core
This article shows how to enable CORS in an ASP.NET Core app. ... For more information, see CORS policy options in this document....
Read more >
Using CORS in Express - Medium
Enabling CORS ​​ The easiest way to get CORS working in Express is by using the cors npm module. That's it. CORS is...
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