/** * Module dependencies. */ var http = require('http') , fs = require('fs'); var args = process.argv.slice(2) , port = args.length ? parseInt(args[0], 10) : 3000; var images = fs.readdirSync(__dirname + '/images').sort(); function list(images) { return '' + images.map(function(path, i){ if ('.gitignore' == path) return ''; return '' + '' + '' + '' + ''; }).join('') + '
TestReference
' + i + '
'; } http.createServer(function(req, res){ switch (req.url) { case '/': res.writeHead(200, { 'Content-Type': 'text/html' }); res.end(list(images)); break; default: fs.readFile(__dirname + '/' + req.url, function(err, buf){ if (err || !buf) { res.writeHead(404, { 'Content-Type': 'text/html' }); res.end('

Not Found

'); } else { res.writeHead(200, { 'Content-Type': 'image/png' , 'Content-Length': buf.length }); res.end(buf); } }); } }).listen(port); console.log('Test image server started on port ' + port);