Skip to content

Instantly share code, notes, and snippets.

@davglass
Forked from darkhelmet/server.js
Created November 19, 2010 12:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davglass/706477 to your computer and use it in GitHub Desktop.
Save davglass/706477 to your computer and use it in GitHub Desktop.
var http = require('http'),
sys = require('sys'),
fs = require('fs'),
url = require('url'),
queryString = require('querystring'),
proxy = require('./htmlfiltre'),
YUI = require('yui3').YUI;
http.createServer(function(req, res) {
proxy.htmlFiltre(req, { foreignHost: 'www.instapaper.com', foreignHostPort: 80 }, function (status, buffer, request, response, loc) {
var headers = response.headers;
if (headers['content-type'].match(/text\/html/)) {
YUI({ debug: true }).use('nodejs-dom', 'event', 'node', function(Y) {
//Just innerHTML the document ;)
Y.config.doc.innerHTML = buffer;
});
sys.puts(JSON.stringify(response.headers));
sys.puts(buffer);
}
res.writeHead('200', headers);
res.write(buffer, 'utf8');
res.end();
}, function(loc) {
res.writeHead('302', { location: loc });
res.end();
});
}).listen(8080);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment