diff --git a/HitTesting.html b/HitTesting.html new file mode 100644 index 0000000000..c5d703b29d --- /dev/null +++ b/HitTesting.html @@ -0,0 +1,104 @@ + + + + + Hit Testing + + + + + + + + diff --git a/css/style.css b/css/style.css new file mode 100644 index 0000000000..1cf7145cda --- /dev/null +++ b/css/style.css @@ -0,0 +1,4 @@ +body { + margin: 0; + overflow: hidden; +} \ No newline at end of file diff --git a/web.js b/web.js index d48dc7cab5..e8c3d1ef0b 100644 --- a/web.js +++ b/web.js @@ -1,21 +1,30 @@ var express = require('express'); var fs = require('fs'); +var util = require('util'); var app = express.createServer(express.logger()); +function send_file(res, file) { + if (!file) return res.send('Not found', 404); + return fs.exists(file, function(exists) { + if (!exists) return res.send('Not found', 404); + return fs.readFile(file, function(err, data) { + if (err) throw err; + return res.send(data.toString('utf8')); + }); + }); +} + app.get('/', function(req, res) { - var buf = fs.readFileSync('index.html'); - res.send(buf.toString('utf8')); + return send_file(res, 'index.html'); +}); + +app.get('/:file', function(req, res) { + return send_file(res, req.params.file); }); -app.get('/js/:file', function(req, res) { - var file = 'js/' + req.params.file; - if (!req.params.file || !fs.existsSync(file)) { - res.send(404, 'Not found'); - } else { - var buf = fs.readFileSync(file); - res.send(buf.toString('utf8')); - } +app.get('/:dir/:file', function(req, res) { + return send_file(res, req.params.dir + '/' + req.params.file); }); var port = process.env.PORT || 5000;