diff --git a/lib/livereload.coffee b/lib/livereload.coffee index ca8cc4d..3f6d4e8 100755 --- a/lib/livereload.coffee +++ b/lib/livereload.coffee @@ -17,6 +17,13 @@ defaultExts = [ defaultExclusions = [/\.git\//, /\.svn\//, /\.hg\//] +defaultHeaders = { + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Methods': 'GET', + 'Access-Control-Allow-Headers': 'cache-control,pragma', + 'Content-Type': 'text/javascript' +} + # Server accepts a Configuration object to configure the server. # # `version`: The protocol version to use. @@ -220,7 +227,7 @@ class Server extends EventEmitter exports.createServer = (config = {}, callback) -> requestHandler = ( req, res )-> if url.parse(req.url).pathname is '/livereload.js' - res.writeHead(200, {'Content-Type': 'text/javascript'}) + res.writeHead(200, defaultHeaders) res.end fs.readFileSync require.resolve 'livereload-js' if !config.https? app = http.createServer requestHandler diff --git a/lib/livereload.js b/lib/livereload.js index 512f7bf..bc6dbaf 100644 --- a/lib/livereload.js +++ b/lib/livereload.js @@ -1,6 +1,6 @@ // Generated by CoffeeScript 1.12.7 (function() { - var EventEmitter, Server, chokidar, defaultExclusions, defaultExts, defaultPort, fs, http, https, path, protocol_version, url, ws, + var EventEmitter, Server, chokidar, defaultExclusions, defaultExts, defaultHeaders, defaultPort, fs, http, https, path, protocol_version, url, ws, extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, hasProp = {}.hasOwnProperty; @@ -28,6 +28,13 @@ defaultExclusions = [/\.git\//, /\.svn\//, /\.hg\//]; + defaultHeaders = { + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Methods': 'OPTIONS, POST, GET', + 'Access-Control-Max-Age': 2592000, + 'Content-Type': 'text/javascript' + }; + Server = (function(superClass) { extend(Server, superClass); @@ -237,9 +244,7 @@ } requestHandler = function(req, res) { if (url.parse(req.url).pathname === '/livereload.js') { - res.writeHead(200, { - 'Content-Type': 'text/javascript' - }); + res.writeHead(200, defaultHeaders); return res.end(fs.readFileSync(require.resolve('livereload-js'))); } };