add content type detection to static.js. no APIs for file mimetypes yet in nodejs ...
This commit is contained in:
parent
695a2420a6
commit
587cfd6447
1 changed files with 19 additions and 2 deletions
21
static.js
Normal file → Executable file
21
static.js
Normal file → Executable file
|
|
@ -1,9 +1,26 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
var http = require("http"),
|
||||
url = require("url"),
|
||||
path = require("path"),
|
||||
fs = require("fs")
|
||||
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
|
||||
|
|
@ -27,9 +44,9 @@ http.createServer(function(request, response) {
|
|||
return;
|
||||
}
|
||||
|
||||
response.writeHead(200);
|
||||
response.writeHead(200, {"Content-Type": guessFileType(filename)});
|
||||
response.write(file, "binary");
|
||||
response.end();
|
||||
});
|
||||
});
|
||||
}).listen(port, "0.0.0.0");
|
||||
}).listen(port, "0.0.0.0");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue