a better approach: use the node-mime plugin
This commit is contained in:
parent
587cfd6447
commit
32b674ce7f
2 changed files with 7 additions and 19 deletions
|
|
@ -28,7 +28,8 @@
|
||||||
"asyncjs": ">=0.0.2",
|
"asyncjs": ">=0.0.2",
|
||||||
"jsdom": ">=0.1.23",
|
"jsdom": ">=0.1.23",
|
||||||
"htmlparser": ">=1.7.2",
|
"htmlparser": ">=1.7.2",
|
||||||
"dryice": ">=0.2.2"
|
"dryice": ">=0.2.2",
|
||||||
|
"mime": ">=1.2.1"
|
||||||
},
|
},
|
||||||
"licenses": [{
|
"licenses": [{
|
||||||
"type": "MPL",
|
"type": "MPL",
|
||||||
|
|
|
||||||
21
static.js
21
static.js
|
|
@ -3,24 +3,10 @@
|
||||||
var http = require("http"),
|
var http = require("http"),
|
||||||
url = require("url"),
|
url = require("url"),
|
||||||
path = require("path"),
|
path = require("path"),
|
||||||
fs = require("fs")
|
fs = require("fs"),
|
||||||
|
mime = require("mime"),
|
||||||
port = process.env.C9_PORT || 8888;
|
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) {
|
http.createServer(function(request, response) {
|
||||||
|
|
||||||
var uri = url.parse(request.url).pathname
|
var uri = url.parse(request.url).pathname
|
||||||
|
|
@ -44,7 +30,8 @@ http.createServer(function(request, response) {
|
||||||
return;
|
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.write(file, "binary");
|
||||||
response.end();
|
response.end();
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue