var http = require("http"),
    url = require("url"),
    path = require("path"),
    fs = require("fs");

//Inits
var port = process.argv[2] || 10631;
var www  = process.argv[3] || path.join(__dirname,"../www/")


////////////////////////////////////////////////////////////////////////
//Utils
////////////////////////////////////////////////////////////////////////
function parseCookies (request) {
    var list = {},
        rc = request.headers.cookie;

    rc && rc.split(';').forEach(function( cookie ) {
        var parts = cookie.split('=');
        list[parts.shift().trim()] = unescape(parts.join('='));
    });

    return list;
}

////////////////////////////////////////////////////////////////////////
// Server
//////////////////////////////////////////////////////////////////////// 
http.createServer(function(request, response) {
 
   var url_parts = url.parse(request.url, true)
    , query = url_parts.query
    , uri = url.parse(request.url).pathname
    , filename = path.join(www, uri)
    , from = request.headers['x-forwarded-for'] || request.connection.remoteAddress;//TODO h ip h to onoma gia na kano login limit

//console.log(from);
console.log(filename);

{
 //Serve static files 
 /*
  * Den yparxei logos na dino to mime type
  * gia kathe typo arxeiou (html,jpg,js,json klp)  
  * mias kai o apache proxy to diorthonei....
  * opote stelno ola xoris mime san binary...
  * 
  */
   
   //Just for fun :) 
   if ((filename.indexOf("serve")>-1)||(filename.indexOf("..")>-1)) {
      response.writeHead(418, {"Content-Type": "text/html"});
      response.write(" 418  I'm a teapot <br />\n Sorry, we don't serve coffee on teapot! <br />\n please see <a href='http://tools.ietf.org/html/rfc2324'>rfc2324</a> and <a href='http://tools.ietf.org/html/rfc7168'>rfc7168</a> <br />\n");
      response.end();
      return;
    }
    
   if ((filename.indexOf("pass")>-1)) {
      response.writeHead(402, {"Content-Type": "text/plain"});
      response.write("402 Pay me to give you access ;) ...\n");
      response.end();
      return;
    }

  fs.exists(filename, function(exists) {
    if(!exists) {
      response.writeHead(404, {"Content-Type": "text/plain"});
      response.write("404 Not Found\n");
      response.end();
      return;
    }
 
    if (fs.statSync(filename).isDirectory()) filename += '/index.html';
 
    fs.readFile(filename, "binary", function(err, file) {
      if(err) {        
        response.writeHead(500, {"Content-Type": "text/plain"});
        response.write("Some error on file reading\n");
        console.log(err);
        response.end();
        return;
      }
      
      response.writeHead(200);
      response.write(file, "binary");
      response.end();
    });
  });

}

}).listen(parseInt(port, 10));
 
console.log("TinyStaticServer running at\n  => http://localhost:" + port + "/\nCTRL + C to shutdown");

@@ -98,16 +98,102 @@
 e(%22fs%22);
+%0Avar mime;%0Atry %7B%0A  mime = require(%22mime%22).lookup;%0A%7D catch(e) %7B%0A  mime = get_mime;   %0A%7D
 %0A%0A//Init
@@ -293,17 +293,16 @@
 www/%22)%0A%0A
-%0A
 ////////
@@ -447,16 +447,91 @@
 ///////%0A
+function getExtension(filename) %7B%0A    return filename.split('.').pop();%0A%7D%0A%0A
 function
@@ -798,16 +798,630 @@
 ist;%0A%7D%0A%0A
+////////////////////////////////////////////////////////////////////////%0A//common mime types (for complete list use node-mime module)%0A////////////////////////////////////////////////////////////////////////%0Afunction get_mime(filename)%7B%0Avar type=%22%22;%0Aswitch(getExtension(filename))%7B%0Acase %22css%22:%0A     type=%22text/css%22;%0Abreak;%0Acase %22htm%22:%0Acase %22html%22:%0A   type=%22text/html%22;%0Abreak;%0Acase %22json%22:%0A   type=%22text/html%22;%0Abreak;%0Acase %22js%22:%0A   type=%22application/json%22;%0Abreak;%0Acase %22jpeg%22:%0Acase %22jpg%22:%0A   type=%22image/jpeg%22;%0Abreak;%0Acase %22png%22:%0A   type=%22image/png%22;%0Abreak;%0Acase %22gif%22:%0A   type=%22image/gif%22;%0Abreak;%0A%7D;%0Areturn type;%0A%7D%0A
 ////////
@@ -1931,16 +1931,18 @@
 (from);%0A
+//
 console.
@@ -1956,16 +1956,16 @@
 ename);%0A
-
 %0A%7B%0A //Se
@@ -1986,213 +1986,11 @@
 es %0A
- /*%0A  * Den yparxei logos na dino to mime type%0A  * gia kathe typo arxeiou (html,jpg,js,json klp)  %0A  * mias kai o apache proxy to diorthonei....%0A  * opote stelno ola xoris mime san binary...%0A  * %0A  */%0A 
   %0A
+
    /
@@ -3197,24 +3197,24 @@
    %7D%0A      %0A
-
       respon
@@ -3229,16 +3229,48 @@
 Head(200
+,%7B%22Content-Type%22:mime(filename)%7D
 );%0A     

add common mime support (if node-mime module exist yhen complete list)