Created
November 2, 2011 05:16
-
-
Save dbarden/1332932 to your computer and use it in GitHub Desktop.
The server modification for Stylus support
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
if (!path.existsSync(localFile)) { | |
response.writeHead(404); | |
response.end(); | |
return; | |
} | |
fs.readFile(localFile, function(error, content) { | |
if (error) { | |
response.writeHead(500); | |
response.end(); | |
} else if (path.extname(localFile).toLowerCase() == '.styl') { | |
var result = ''; | |
var str = require('fs').readFileSync(localFile, 'utf8'); | |
stylus.render(str, { filename: path.basename(localFile) }, function(err, css){ | |
if (err) { | |
response.writeHead(500); | |
response.end(); | |
} | |
console.log(css); | |
result = css; | |
}); | |
// Chameleon is currently only designed to support css. | |
response.writeHead(200, { 'Content-Type': 'text/css' }); | |
response.end(result, 'utf-8'); | |
} else { | |
response.writeHead(200, { 'Content-Type': 'text/css' }); | |
response.end(content, 'utf-8'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment