diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2013-10-22 20:40:50 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2013-10-22 20:40:50 +0200 |
commit | 34e60841a44ee688792e87863aa67db469d39fa8 (patch) | |
tree | d4ec57728121d87b029d8b729c98494356015061 /test/data | |
parent | 4452df33f080c314f9b4c6a6504f254edc500282 (diff) | |
download | appstore-34e60841a44ee688792e87863aa67db469d39fa8.tar.gz appstore-34e60841a44ee688792e87863aa67db469d39fa8.tar.bz2 appstore-34e60841a44ee688792e87863aa67db469d39fa8.tar.xz appstore-34e60841a44ee688792e87863aa67db469d39fa8.zip |
wip
Diffstat (limited to 'test/data')
-rw-r--r-- | test/data/my-webapp/root/app.js | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/test/data/my-webapp/root/app.js b/test/data/my-webapp/root/app.js new file mode 100644 index 0000000..29298b3 --- /dev/null +++ b/test/data/my-webapp/root/app.js @@ -0,0 +1,37 @@ +var http = require("http"), + url = require("url"), + path = require("path"), + fs = require("fs") + port = process.env.PORT || 8888; + +http.createServer(function(request, response) { + + var uri = url.parse(request.url).pathname + , filename = path.join(process.cwd(), uri); + + path.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(err + "\n"); + response.end(); + return; + } + + response.writeHead(200); + response.write(file, "binary"); + response.end(); + }); + }); +}).listen(parseInt(port, 10)); + +console.log("Static file server running at\n => http://localhost:" + port + "/\nCTRL + C to shutdown"); |