Mercurial > eldonilo > avatar
changeset 7:51cda3a6e1c3
Better handling of proxy connections; add an option to specify the root on the webserver.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Thu, 19 May 2011 19:36:53 +0200 |
parents | 3b799c33ab16 |
children | e0cd5ede76af |
files | avatar.js configuration.js |
diffstat | 2 files changed, 6 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- 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'});
--- 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.