# HG changeset patch # User Emmanuel Gil Peyrot # Date 1305826613 -7200 # Node ID 51cda3a6e1c336126eb2f9b3c16232940b83a8ad # Parent 3b799c33ab16748963e4f5ecc95bc5fcfb621704 Better handling of proxy connections; add an option to specify the root on the webserver. diff --git a/avatar.js b/avatar.js --- a/avatar.js +++ b/avatar.js @@ -239,11 +239,11 @@ fs.readdir('data', function(err, files) }); http.createServer(function (req, res) { - console.log('Connection from '+req.client.remoteAddress+' ('+req.headers['user-agent']+') to get “'+req.url+'”.'); + console.log('Connection from ' + (req.headers['x-forwarded-for'] || req.client.remoteAddress) + ' (' + req.headers['user-agent'] + ') to get “' + req.url + '”.'); var easterEggs = { source: { - re: /^\/avatar\/source\/code$/, + re: new RegExp(config.webRoot + 'source/code$'), file: process.argv[1], mime: 'application/ecmascript', error: 'source code unavailable! oO' @@ -257,7 +257,7 @@ http.createServer(function (req, res) { for (var i in easterEggs) { var ee = easterEggs[i]; var file = ee.file || i; - var re = ee.re || new RegExp('^/avatar/'+file+'$'); + var re = ee.re || new RegExp(config.webRoot + file + '$'); if (re.test(req.url)) { fs.readFile(file, function(err, content) { if (err) { @@ -271,7 +271,7 @@ http.createServer(function (req, res) { } } - var jid = unescape(req.url.replace(/^\/avatar\//, '')); + var jid = unescape(req.url.replace(new RegExp(config.webRoot), '')); if (jid === '') { res.writeHead(200, {'Content-Type': 'application/xhtml+xml'}); diff --git a/configuration.js b/configuration.js --- a/configuration.js +++ b/configuration.js @@ -24,5 +24,7 @@ config.jid = 'avatar.example.org'; config.host = 'localhost'; config.port = 5347; config.password = 'hellohello'; + +config.webRoot = '^/avatar/'; config.directory = 'data'; // Directory of the cache. config.guessType = false; // When true, assume that the TYPE of the avatar is image/png if not specified.