Created
July 1, 2012 07:10
-
-
Save austinyun/3027255 to your computer and use it in GitHub Desktop.
Javascript killing the syntax file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require('http'), | |
fs = require('fs'), | |
utils = require('util'), | |
git = require('git-fs'), | |
path = require('path'), | |
router = require('choreographer').router(); | |
module.exports = function rice() { | |
// Initialize git-fs with the cwd | |
git(process.cwd()); | |
router.get('/favicon.ico', function (req, res) { | |
fs.readFile('favicon.ico', function (err, icon) { | |
if (err) { | |
throw err; | |
} | |
res.writeHead(200, { | |
'Content-Type': 'image/x-icon'; | |
}); | |
res.end(icon); | |
}); | |
}); | |
router.get('/*', function (req, res) { | |
console.error("route hit"); | |
git.readFile("fs", req.url, function (err, data) { | |
if (err) { | |
throw err; | |
} | |
console.log(data.toString()); | |
res.end(data.toString()); | |
}); | |
}); | |
router.notFound(function (req, res) { | |
res.writeHead(404, { | |
'Content-Type': 'text/plain' | |
}); | |
res.end('Error 404: ' + req.url + ' not found.'); | |
}); | |
return http.createServer(router); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment