Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

connect-livereload

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

connect-livereload - npm Package Compare versions

Comparing version 0.5.3 to 0.5.4

27

index.js
module.exports = function livereload(opt) {
// options
var opt = opt || {};
opt = opt || {};
var ignore = opt.ignore || opt.excludeList || [/\.js(\?.*)?$/, /\.css(\?.*)?$/, /\.svg(\?.*)?$/, /\.ico(\?.*)?$/,
/\.woff(\?.*)?$/, /\.png(\?.*)?$/, /\.jpg(\?.*)?$/, /\.jpeg(\?.*)?$/, /\.gif(\?.*)?$/, /\.pdf(\?.*)?$/
];
/\.woff(\?.*)?$/, /\.png(\?.*)?$/, /\.jpg(\?.*)?$/, /\.jpeg(\?.*)?$/, /\.gif(\?.*)?$/, /\.pdf(\?.*)?$/,
/\.json(\?.*)?$/
];

@@ -21,7 +22,9 @@ var include = opt.include || [/.*/];

var disableCompression = opt.disableCompression || false;
var hostname = opt.hostname || 'localhost';
var port = opt.port || 35729;
var src = opt.src || "//' + (location.hostname || '" + hostname + "') + ':" + port + "/livereload.js?snipver=1";
var snippet = "\n<script>//<![CDATA[\ndocument.write('<script src=\"" + src + "\"><\\/script>')\n//]]></script>\n";
function snippet(host) {
var src = opt.src || '//' + host + ':' + port + '/livereload.js?snipver=1';
return '<script src="' + src + '" async="" defer=""></script>';
}
// helper functions

@@ -59,8 +62,8 @@ var regex = (function () {

function snap(body) {
function snap(body, host) {
var _body = body;
rules.some(function (rule) {
if (rule.match.test(body)) {
_body = body.replace(rule.match, function (w) {
return rule.fn(w, snippet);
_body = body.replace(rule.match, function(w) {
return rule.fn(w, snippet(host));
});

@@ -90,2 +93,4 @@ return true;

return function livereload(req, res, next) {
var host = opt.hostname || req.headers.host.split(':')[0];
if (res._livereload) return next();

@@ -119,3 +124,3 @@ res._livereload = true;

if (exists(body) && !snip(res.data)) {
res.push(snap(body));
res.push(snap(body, host));
return true;

@@ -159,3 +164,3 @@ }

// Include, if necessary, replacing the entire res.data with the included snippet.
res.data = snap(res.data);
res.data = snap(res.data, host);
}

@@ -162,0 +167,0 @@ if (res.data !== undefined && !res._header) res.setHeader('content-length', Buffer.byteLength(res.data, encoding));

{
"name": "connect-livereload",
"description": "connect middleware for adding the livereload script to the response",
"version": "0.5.3",
"version": "0.5.4",
"author": "Andi Neck <andi.neck@intesso.com>",

@@ -30,2 +30,3 @@ "contributors": [

"main": "index",
"license": "MIT",
"engines": {

@@ -32,0 +33,0 @@ "node": "*"

@@ -95,2 +95,5 @@

src: "http://localhost:35729/livereload.js?snipver=1",
// Set this option to `true` to set `req.headers['accept-encoding']` to 'identity' (disabling compression)
disableCompression: false,
```

@@ -97,0 +100,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc