annotate nodejs-server/server.js @ 2:60e254d948c2

some server confic mods
author gyorgyf
date Sat, 16 Jun 2012 21:59:05 +0100
parents 89a05584e39e
children 9d2f4e6a3f36
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;
gyorgyf@0 12 case '/moods.csv':
gyorgyf@0 13 res.end(fs.readFileSync("moods.csv"));
gyorgyf@0 14 res.writeHead(200, {'Content-Type': 'text/plain'});
gyorgyf@0 15 break;
gyorgyf@0 16 case '/app.js':
gyorgyf@0 17 res.end(fs.readFileSync("app.js"));
gyorgyf@0 18 res.writeHead(200, {'Content-Type': 'text/javascript'});
gyorgyf@0 19 break;
gyorgyf@0 20 default:
gyorgyf@0 21 res.end(fs.readFileSync("index.html"));
gyorgyf@0 22 res.writeHead(404, {'Content-Type': 'text/plain'});
gyorgyf@0 23 }
gyorgyf@0 24 }).listen(3000, "127.0.0.1");