tweetcast/nodejs/node-direct.js
changeset 334 b7f05d66b620
parent 332 738594562e44
child 335 5f83c21dee69
equal deleted inserted replaced
333:4389fd4ae58f 334:b7f05d66b620
   165         }
   165         }
   166     }
   166     }
   167 }
   167 }
   168 
   168 
   169 function httpHandler(req, res) {
   169 function httpHandler(req, res) {
       
   170     console.log("HTTP Request for URL "+req.url);
   170     var url = req.url + ( req.url[req.url.length - 1] == "/" ? "index.html" : "" );
   171     var url = req.url + ( req.url[req.url.length - 1] == "/" ? "index.html" : "" );
   171     fs.readFile(__dirname + "/client" + url, function(err, data) {
   172     fs.readFile(__dirname + "/client" + url, function(err, data) {
   172         if (err) {
   173         if (err) {
       
   174             console.log("Error 404");
   173             res.writeHead(404);
   175             res.writeHead(404);
   174             return res.end('File not found');
   176             return res.end('File not found');
   175         }
   177         }
   176         res.writeHead(200);
   178         res.writeHead(200);
   177         res.end(data);
   179         res.end(data);