Skip to content

Instantly share code, notes, and snippets.

@ncb000gt
Created September 1, 2010 02:09
Show Gist options
  • Save ncb000gt/560111 to your computer and use it in GitHub Desktop.
Save ncb000gt/560111 to your computer and use it in GitHub Desktop.
var sys = require("sys"),
http = require("http"),
fs = require('fs'),
path = require('path');
http.createServer(function(request, response) {
var headers = { "Content-Type": "text/html" };
var filename = path.join(process.cwd(), 'work/terminix/knox/index.html');
path.exists(filename, function(exists) {
if(!exists) {
response.writeHead(404, headers);
response.end("<!DOCTYPE html><html><head><title>404 error</title></head><body><h1>404 error</h1></body></html>")
return;
}
else {
fs.readFile(filename, function(err, file_content) {
if(err) {
throw err;
}
/*************************/
if (filename.indexOf('.jpg') > 0) headers['Content-Type'] = 'image/jpeg';
/*************************/
response.writeHead(200, headers);
// sys.debug('content: ' + file_content);
response.end(file_content);
});
}
});
}).listen(8000);
sys.puts("> Running at port 8000");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment