Created
January 12, 2012 22:03
-
-
Save jchillerup/1603424 to your computer and use it in GitHub Desktop.
remote reloading of web content with socket.io and node
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var socket = io.connect('http://HOSTNAME:8080'); | |
socket.on('reload', function (data) { | |
location.reload(); | |
}); | |
/* | |
socket.on('eval', function(data) { | |
eval(data.evalString); | |
}); | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.