live-server
Advanced tools
Comparing version 0.1.1 to 0.2.0
@@ -13,2 +13,4 @@ #!/usr/bin/env node | ||
var INJECTED_CODE = require('fs').readFileSync(__dirname + "/injected.html", "utf8"); | ||
function escape(html){ | ||
@@ -43,14 +45,7 @@ return String(html) | ||
if (x == "" || x == ".html" || x == ".htm" || x == ".xhtml" || x == ".php") { | ||
var code = "<script>\n(function() {\n" + | ||
"protocol = window.location.protocol === 'http:' ? 'ws://' : 'wss://';\n" + | ||
"address = protocol + window.location.host + window.location.pathname + '/ws';\n" + | ||
"socket = new WebSocket(address);\n" + | ||
"socket.onmessage = function(msg) { msg.data == 'reload' && window.location.reload() };\n" + | ||
"console.log('Live reload enabled.');\n" + | ||
"})();\n</script>"; | ||
// We need to modify the length given to browser | ||
var len = code.length + res.getHeader('Content-Length'); | ||
var len = INJECTED_CODE.length + res.getHeader('Content-Length'); | ||
res.setHeader('Content-Length', len); | ||
// Write the injected code | ||
res.write(code); | ||
res.write(INJECTED_CODE); | ||
} | ||
@@ -85,4 +80,7 @@ } | ||
ignorePatterns: true, | ||
listener: function(eventName, filePath, fileCurrentStat, filePreviousStat){ | ||
ws && ws.send('reload'); | ||
ignoreHiddenFiles: true, | ||
listener: function(eventName, filePath, fileCurrentStat, filePreviousStat) { | ||
if (!ws) return; | ||
if (path.extname(filePath) == ".css") ws.send('refreshcss'); | ||
else ws.send('reload'); | ||
} | ||
@@ -89,0 +87,0 @@ }); |
{ | ||
"name": "live-server", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "simple development http server with live reload capability", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -38,3 +38,3 @@ Live Server | ||
This will automatically launch the default browser (you should have `index.html` present). When you make a change to any file, the browser will reload the page. | ||
This will automatically launch the default browser (you should have `index.html` present). When you make a change to any file, the browser will reload the page - unless it was a CSS file in which case the changes are applied without a reload. | ||
@@ -41,0 +41,0 @@ You can configure the port to be used by setting `PORT` environment variable prior to launching the server. |
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
7346
5
82
2