Skip to content

Commit

Permalink
replace custom script with replacestream
Browse files Browse the repository at this point in the history
  • Loading branch information
w33ble committed Apr 22, 2014
1 parent 275274e commit e90c4e7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 17 deletions.
9 changes: 7 additions & 2 deletions lib/serve/createServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var http = require('http');
var pf = require('portfinder');
var mime = require('mime');
var exec = require('child_process').exec;
var lrStream = require('../util/liveReloadStream');
var rstream = require('replacestream');

module.exports = function (port, lrPort, open, next) {
var server = http.createServer(function(req, res) {
Expand All @@ -26,8 +26,9 @@ module.exports = function (port, lrPort, open, next) {

// if html, inject lr
if (filePath.match(/htm(l)?$/)) {
console.log('html');
fileStream
.pipe(lrStream(lrPort))
.pipe(rstream('</body>', getLivereloadTag(lrPort)+'</body>'))
.pipe(res);
} else {
// stream file to response
Expand All @@ -48,6 +49,10 @@ module.exports = function (port, lrPort, open, next) {
});
};

function getLivereloadTag(port) {
return "<script>document.write('<script src=\"http://' + (location.host || 'localhost').split(':')[0] + ':"+port+"/livereload.js?snipver=1\"></' + 'script>')</script>";
}

function send404(res) {
res.writeHead(404, {'Content-type': 'text/plain'});
res.end('Not Found');
Expand Down
14 changes: 0 additions & 14 deletions lib/util/liveReloadStream.js

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"portfinder": "~0.2.1",
"minimist": "0.0.8",
"mime": "~1.2.11",
"through2-map": "~1.2.1"
"replacestream": "~0.1.3"
},
"devDependencies": {
"mocha": "*",
Expand Down

0 comments on commit e90c4e7

Please sign in to comment.