Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# node-proxy-injector

A script that allows you to proxy a remote server and inject css stylesheets and js scripts into the remote server response. The tool supports live reload, but you must have browser extensions installed and configured. For details visit http://help.livereload.com/kb/general-use/browser-extensions.
A script that allows you to proxy a remote server and inject css stylesheets and js scripts into the remote server response. The tool supports live reload.

Note that this tool is a work in progress!

Expand Down
9 changes: 9 additions & 0 deletions lib/proxy-injector.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var createProxyServer = function(config) {
processHtmlData(res)
.then(function(htmlData) {
var html = injectFiles(htmlData, _targetFiles);
html = injectLiveReload(html);
clientRes.end(html);
}, logErrorAndExit);
};
Expand Down Expand Up @@ -110,6 +111,14 @@ var injectFiles = function(htmlData, files) {
return $.html();
};

var injectLiveReload = function (html) {
return html.replace('</body>',
"<script>document.write('<script src=\"http://' + " +
"(location.host || 'localhost').split(':')[0] + ':35729" +
"/livereload.js?snipver=1\"></' + 'script>')</script></body>"
);
};

var appendFile = function(node, tag) {
return function(file) {
var data = fs.readFileSync(file, 'utf8');
Expand Down
3 changes: 1 addition & 2 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ console.log("Proxy server listening on port", options.proxyPort);

// Live reload server watching for files in target directory
var livereloadServer = livereload.createServer({
originalPath: 'http://localhost:' + options.proxyPort,
applyCSSLive: false
});
}); // default port
livereloadServer.watch(options.targetDir);