Skip to content

Instantly share code, notes, and snippets.

@adambard
Last active March 29, 2016 07:07
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 adambard/f11292c891bf53eb3286 to your computer and use it in GitHub Desktop.
Save adambard/f11292c891bf53eb3286 to your computer and use it in GitHub Desktop.
url = require('url')
http = require('http')
https = require('https')
r = require('readability-node')
jsdom = require('jsdom').jsdom
function handleRequest(request, response){
var uri = url.parse(request.url, true).query.url;
uri = url.parse(uri || "https://medium.com/@mbostock/what-makes-software-good-943557f8a488")
https.get(uri, function(res){
console.log("Got response", res.statusCode)
var src = '';
res.on('data', function(d){ src += d; });
res.on('end', function(){
console.log("Stream end");
// Do something with src
var doc = jsdom(src, {features: {
FetchExternalResources: false,
ProcessExternalResources: false
}
});
var article = new r.Readability(uri, doc).parse();
response.end(
"<html><head><meta charset=\"UTF-8\"></head><body>" +
"<h1>" + article.title + "</h1>" +
article.content +
"</body></html>");
});
}).on('error', function(e){
console.log("Got error", e.message)
});
}
var server = http.createServer(handleRequest);
server.listen(3000, function(){ console.log("OK");});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment