Skip to content

Instantly share code, notes, and snippets.

@jchillerup
Created January 12, 2012 22:03
Show Gist options
  • Save jchillerup/1603424 to your computer and use it in GitHub Desktop.
Save jchillerup/1603424 to your computer and use it in GitHub Desktop.
remote reloading of web content with socket.io and node
var socket = io.connect('http://HOSTNAME:8080');
socket.on('reload', function (data) {
location.reload();
});
/*
socket.on('eval', function(data) {
eval(data.evalString);
});
*/
var io = require('socket.io').listen(8080);
var http = require('http');
io.sockets.on('connection', function (socket) {
// nothing currently
});
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Reloading clients\n');
io.sockets.emit('reload', {});
}).listen(1337, "HOSTNAME");
console.log('Server running at http://HOSTNAME:1337/');
@pmuellr
Copy link

pmuellr commented Jan 13, 2012

I don't see it as a hook to wr, at least yet, but a standalone command I would add to my Makefile. If I ever server-ize wr, then I think maybe it would make sense to add it there, somehow.

w/r/t auth. Nope. I'd say, for the first pass, no auth, but you only run the server so it accepts connections from localhost. Safe enough. The biggest security hole would be shipping your code with the reloader script still in it. People have shipped pages in production that included the weinre target bits, which is the same, horrendous, security exposure. Or an awesome hack, whatever your tastes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment