I’ve been able to pull pages from wikipedia and serve them from localhost with the code below. I want to be able to change the logo also. I attempted to do that with the .replace() function but it’s not working.
var http = require('http');
http.createServer(function (req, res) {
console.log(req.url)
var options = {
host: 'en.wikipedia.org',
port: 80,
path: req.url,
};
var req = http.get(options, function(response) {
response.setEncoding('utf8');
response.on('data', function (chunk) {
chunk.replace("http://upload.wikimedia.org/wikipedia/en/b/bc/Wiki.png","http://www.sotmclub.com/images/logo.png");
res.write(chunk, 'utf8');
});
res.writeHead(response.statusCode, response.headers);
});
}).listen(1337, "127.0.0.1");
Strings in javascript are immutable. All
chunk.replaceis doing is returning a new string. You have to instead dochunk = chunk.replace(...).