a better approach: use the node-mime plugin

This commit is contained in:
Mihai Sucan 2011-02-15 20:09:19 +08:00 коммит произвёл Fabian Jakobs
Родитель 587cfd6447
Коммит 32b674ce7f
2 изменённых файлов: 7 добавлений и 19 удалений

Просмотреть файл

@ -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"
}]
}
}

Просмотреть файл

@ -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();
});