Skip to content

Instantly share code, notes, and snippets.

@dbarden
Created November 2, 2011 05:16
Show Gist options
  • Save dbarden/1332932 to your computer and use it in GitHub Desktop.
Save dbarden/1332932 to your computer and use it in GitHub Desktop.
The server modification for Stylus support
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