Ppb2011 1
var http = require('http');
var url = require('url');
 
var server = http.createServer(
  function(req, res) {
 
    pathname = decodeURIComponent(url.parse(req.url).pathname).split('/')[1];
    console.log(pathname);
 
    if (pathname === 'kill') {
      res.writeHead(200, {"Content-Type": "text/html; charset=UTF-8"});
      res.end("<h1>Server кирдык<h1>");
      server.close('');
      req.connection.destroy('');
      console.log("кирдык");
      process.exit('');
      return;
    }
 
    map=pathname.split(' ');
    console.log(map);
    res.writeHead(200,{"Content-Type": "application/json; charset=UTF-8"});
 
    d = parseInt(map[0]);
    m = parseInt(map[1]);
    y = parseInt(map[2]);
 
    tomorrow = new Date(y, m-1, d, 0, 0, 0, 0);
    tomorrow.setDate(tomorrow.getDate() + 1);
    result = tomorrow.getDate() + " " + (tomorrow.getMonth()+1) + " " + tomorrow.getFullYear();
 
    res.end(JSON.stringify({server:'Сервис определения даты завтрашнего дня', pathname:pathname, request:map, result:result}));
});
 
server.listen(8000)
console.log('Сервер стартовал на порту 8000')