Skip to content

Instantly share code, notes, and snippets.

@Siedrix
Created May 15, 2013 20:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Siedrix/5587199 to your computer and use it in GitHub Desktop.
Save Siedrix/5587199 to your computer and use it in GitHub Desktop.
var socket = io.connect('http://192.168.1.118:3500');
console.log('jump', io, socket);
socket.on('jump', function(data){
window.location = 'http://192.168.1.118:3500/?page=' + data.url;
});
//dentro del folder de public
var express = require('express'),
request = require('request'),
http = require('http');
var jsdom = require("jsdom");
var app = express();
var server = http.createServer(app);
var io = require('socket.io').listen(server);
app.use( express.static('./public') );
app.get('/', function(req, res){
request.get(req.query.page, function(err, response, body){
console.log('send', req.query.page);
jsdom.env(
body,
["http://code.jquery.com/jquery.js"],
function(errors, window) {
window.$('link').each(function(i,item){
var $item = window.$(item);
var href = $item.attr('href')
if(!href.match(/http/)){
href = req.query.page + '/' + href;
}
$item.attr('href', href);
});
var body = window.$("html").html();
body = body.replace('</body>',
'<script src="http://192.168.1.118:3500/socket.io/socket.io.js"></script>\
<script src="http://192.168.1.118:3500/jump.js"></script>\
<script>window.page = "'+req.query.page+'"</script>\
</body>');
res.send(body);
}
);
});
});
app.get('/jump', function(req, res){
io.sockets.emit('jump', {
url : req.query.page
});
res.send('jumping');
});
server.listen(3500);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment