Skip to content

Instantly share code, notes, and snippets.

@usagi
Created July 3, 2012 01:38
Show Gist options
  • Select an option

  • Save usagi/3036992 to your computer and use it in GitHub Desktop.

Select an option

Save usagi/3036992 to your computer and use it in GitHub Desktop.
var http = require("http");
var fs = require("fs");
var path = require("path");
http.createServer
( function(request, response)
{ var filename = request.url.substr(1);
if (path.existsSync(filename))
{ response.writeHead
( 200
, {"Content-Type": "text/plain"}
);
response.write
( request.url + "\n"
+ "----------" + "\n"
);
response.write
( fs.readFileSync(filename)
, 'utf-8'
);
} else
{ response.writeHead(404);
}
response.end();
}
).listen(80);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment