Skip to content
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

feature request: support CORS for hosts #159

Closed
lifeart opened this issue Oct 8, 2021 · 1 comment
Closed

feature request: support CORS for hosts #159

lifeart opened this issue Oct 8, 2021 · 1 comment

Comments

@lifeart
Copy link

lifeart commented Oct 8, 2021

Use case:

  • Static Java application with it's own serving logic and host (dev.foo.bar)
  • Frontend Development & LiveReload server running in parallel, to simplify frontend development (host: localhost)

We point to live-reload script and getting CORS error.

Desired behavour:

LiveReload server has option, to configure "allowed" host.

  • we could add "if" condition to check for "origin" value, and apply CORS headers if exists.
  • config.origin is full host: https://foo.bar:80
diff --git a/node_modules/livereload/lib/livereload.js b/node_modules/livereload/lib/livereload.js
index 512f7bf..c68ff2e 100644
--- a/node_modules/livereload/lib/livereload.js
+++ b/node_modules/livereload/lib/livereload.js
@@ -237,9 +237,13 @@
     }
     requestHandler = function(req, res) {
       if (url.parse(req.url).pathname === '/livereload.js') {
-        res.writeHead(200, {
-          'Content-Type': 'text/javascript'
-        });
+        const headers = {
+          'Content-Type': 'text/javascript',
+          'Access-Control-Allow-Methods': 'GET, OPTIONS',
+          'Access-Control-Allow-Origin': config.origin
+        };
+        // corsDomains
+        res.writeHead(200, headers);
         return res.end(fs.readFileSync(require.resolve('livereload-js')));
       }
     };
@napcs
Copy link
Owner

napcs commented Oct 12, 2021

See #155. Discussing this there.

@lifeart lifeart closed this as completed Oct 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants