Skip to content

Instantly share code, notes, and snippets.

@azybler
Created March 26, 2013 10:06
Show Gist options
  • Save azybler/5244301 to your computer and use it in GitHub Desktop.
Save azybler/5244301 to your computer and use it in GitHub Desktop.
var http = require('http');
var Chimera = require('chimera').Chimera;
var fs = require('fs');
var c = new Chimera();
var server = http.createServer(function(req, res) {
if (req.method === 'GET' && req.url === '/') {
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(" \
<html> \
<head> \
<style> \
body,html { padding:0; margin:0; } \
</style> \
<script src='//cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js'></script> \
</head> \
<body> \
<div style='background-color:#ccc;padding:5px'> \
<label for='url' style='font-weight:bold'>URL</label>: \
<input id='url' value='' size='65' style='padding:5px'> \
<button id='crawlpage-btn' style='padding:5px'>Crawl</button> \
</div> \
<div id='dynamic-body' style='padding:5px'> \
</div> \
<script> \
$(document).ready(function() { \
$('#url').focus(); \
}); \
var inProgress = false; \
$('#crawlpage-btn').click(function() { \
if (inProgress === true) return; \
inProgress = true; \
$('#crawlpage-btn').attr('disabled', true); \
$('#url').attr('disabled', true); \
$('#dynamic-body').html('<img style=\"padding-right:5px\" width=\"30\" height=\"30\" src=\"http://www.sixbillionsecrets.com/images/ajax_loader.gif\"/>Loading, please be very patient...'); \
$.get('crawl_page?url=' + encodeURI($('#url').val()), function(data) { \
inProgress = false; \
$('#dynamic-body').html(data); \
$('#crawlpage-btn').attr('disabled', false); \
$('#url').attr('disabled', false); \
}); \
}); \
</script> \
</body> \
</html>");
} else if (req.method === 'GET' && req.url.substring(0, 16) === '/crawl_page?url=') {
var url = decodeURI(req.url.substring(16));
var t = Date.now();
c.perform({
url: url,
locals: { },
run: function(callback) {
callback(null, 'success');
},
callback: function(err, result) {
if (err === null) {
res.writeHead(200, { 'Content-Type': 'image/html' });
res.end('DONE');
}
c.close();
}
});
}
});
server.listen(8082);
console.log("Server running at http://127.0.0.1:8082/");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment