annotate nodejs-server/server.js @ 54:c0b34039917a tip

Server: added an exposed function to log the start time of a performance (for log-to-audio sync)
author Mathieu Barthet <mathieu.barthet@eecs.qmul.ac.uk>
date Wed, 14 Oct 2015 19:20:08 +0100
parents c84bcf573b31
children
rev   line source
gyorgyf@0 1 var http = require('http');
gyorgyf@0 2 var fs = require('fs');
gyorgyf@0 3
gyorgyf@0 4 http.createServer(function (req, res) {
gyorgyf@0 5 console.log(req.url);
gyorgyf@0 6
gyorgyf@0 7 switch (req.url) {
gyorgyf@0 8 case '/mood':
gyorgyf@0 9 res.end("{status:'ok'}");
gyorgyf@0 10 res.writeHead(200, {'Content-Type': 'application/json'});
gyorgyf@0 11 break;
mgeorgi@6 12 case '/colors.txt':
mgeorgi@6 13 res.end(fs.readFileSync("colors.txt"));
mgeorgi@6 14 res.writeHead(200, {'Content-Type': 'text/plain'});
mgeorgi@6 15 break;
gyorgyf@0 16 case '/moods.csv':
gyorgyf@0 17 res.end(fs.readFileSync("moods.csv"));
gyorgyf@0 18 res.writeHead(200, {'Content-Type': 'text/plain'});
gyorgyf@0 19 break;
gyorgyf@0 20 case '/app.js':
gyorgyf@0 21 res.end(fs.readFileSync("app.js"));
gyorgyf@0 22 res.writeHead(200, {'Content-Type': 'text/javascript'});
gyorgyf@0 23 break;
gyorgyf@0 24 default:
gyorgyf@0 25 res.end(fs.readFileSync("index.html"));
gyorgyf@0 26 res.writeHead(404, {'Content-Type': 'text/plain'});
gyorgyf@0 27 }
mgeorgi@18 28 }).listen(80, "0.0.0.0");