connect-livereload
Advanced tools
Comparing version 0.4.1 to 0.5.0
21
index.js
module.exports = function livereload(opt) { | ||
// options | ||
var opt = opt || {}; | ||
var ignore = opt.ignore || opt.excludeList || [/\.js$/, /\.css$/, /\.svg$/, /\.ico$/, /\.woff$/, /\.png$/, /\.jpg$/, /\.jpeg$/]; | ||
var ignore = opt.ignore || opt.excludeList || | ||
[/\.js(\?.*)?$/, /\.css(\?.*)?$/, /\.svg(\?.*)?$/, /\.ico(\?.*)?$/, /\.woff(\?.*)?$/, /\.png(\?.*)?$/, /\.jpg(\?.*)?$/, /\.jpeg(\?.*)?$/]; | ||
var include = opt.include || [/.*/]; | ||
@@ -114,11 +115,11 @@ var html = opt.html || _html; | ||
var body = string instanceof Buffer ? string.toString(encoding) : string; | ||
// If this chunk must receive a snip, do so | ||
if (exists(body) && !snip(res.data)) { | ||
res.push(snap(body)); | ||
return true; | ||
} else if (html(body) || html(res.data)) { | ||
} | ||
// If in doubt, simply buffer the data for later inspection (on `end` function) | ||
else { | ||
res.push(body); | ||
return true; | ||
} else { | ||
restore(); | ||
return write.call(res, string, encoding); | ||
} | ||
@@ -146,5 +147,11 @@ } | ||
res.end = function(string, encoding) { | ||
// If there are remaining bytes, save them as well | ||
// Also, some implementations call "end" directly with all data. | ||
res.inject(string); | ||
restore(); | ||
var result = res.inject(string, encoding); | ||
if (!result) return end.call(res, string, encoding); | ||
// Check if our body is HTML, and if it does not already have the snippet. | ||
if (html(res.data) && exists(res.data) && !snip(res.data)) { | ||
// Include, if necessary, replacing the entire res.data with the included snippet. | ||
res.data = snap(res.data); | ||
} | ||
if (res.data !== undefined && !res._header) res.setHeader('content-length', Buffer.byteLength(res.data, encoding)); | ||
@@ -151,0 +158,0 @@ res.end(res.data, encoding); |
{ | ||
"name": "connect-livereload", | ||
"description": "connect middleware for adding the livereload script to the response", | ||
"version": "0.4.1", | ||
"version": "0.5.0", | ||
"author": "Andi Neck <andi.neck@intesso.com>", | ||
@@ -6,0 +6,0 @@ "contributors": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11327
139