diff --git a/package.json b/package.json index 7dc7653d..1fdb73dc 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,8 @@ "asyncjs": ">=0.0.2", "jsdom": ">=0.1.23", "htmlparser": ">=1.7.2", - "dryice": ">=0.2.2" + "dryice": ">=0.2.2", + "mime": ">=1.2.1" }, "licenses": [{ "type": "MPL", @@ -42,4 +43,4 @@ "type": "LGPL", "url": "http://www.gnu.org/licenses/lgpl.html" }] -} \ No newline at end of file +} diff --git a/static.js b/static.js index 05af810a..dee2a6aa 100755 --- a/static.js +++ b/static.js @@ -3,24 +3,10 @@ var http = require("http"), url = require("url"), path = require("path"), - fs = require("fs") + fs = require("fs"), + mime = require("mime"), port = process.env.C9_PORT || 8888; -function guessFileType(name) { - var types = { - '.html': 'text/html', - '.xhtml': 'application/xhtml+xml', - '.js': 'text/javascript', - '.css': 'text/css', - '.png': 'image/png', - '.jpg': 'image/jpeg', - }; - - var ext = path.extname(name); - - return ext in types ? types[ext] : 'text/plain'; -} - http.createServer(function(request, response) { var uri = url.parse(request.url).pathname @@ -44,7 +30,8 @@ http.createServer(function(request, response) { return; } - response.writeHead(200, {"Content-Type": guessFileType(filename)}); + var contentType = mime.lookup(filename) || "text/plain"; + response.writeHead(200, {"Content-Type": contentType}); response.write(file, "binary"); response.end(); });