diff --git a/static.js b/static.js old mode 100644 new mode 100755 index a08f00bf..05af810a --- a/static.js +++ b/static.js @@ -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"); \ No newline at end of file +}).listen(port, "0.0.0.0");