Skip to content

Instantly share code, notes, and snippets.

@wess
Created August 24, 2010 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wess/547567 to your computer and use it in GitHub Desktop.
Save wess/547567 to your computer and use it in GitHub Desktop.
(function() {
var http = require('http'),
fs = require('fs'),
url = require('url'),
conf = require('./conf').FosterConfig;
var server = http.createServer();
server.addListener('request', function(data, response){
if(data.url !== '/favicon.ico')
{
var currentUrl = url.parse(data.url).pathname;
var cwd = process.cwd();
var filePath = cwd + currentUrl;
fs.readFile(filePath, function(err, data){
if(err)
{
var responseText = "<html><body><h1>404 Error:</h1><p>Could not locate: " + filePath + "</p></body></html>";
response.writeHead(200, {
"Content-Length": responseText.length,
"Content-Type": "text/html"
});
console.log("\033[22;31m404: Cannot locate: " + filePath + "\033[0m");
response.end(responseText);
}
else
{
response.writeHead(200, {
"Content-Length": data.length,
"Content-Type": "text/html"
});
console.log("\033[22;32mLoading: " + filePath + "\033[0m");
response.end(data);
}
})
}
})
console.log("\033[22;32mStarting Foster Dev server at: " + conf.server.host + ":" + conf.server.port + "\033[0m");
server.listen(conf.server.port, conf.server.host);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment