Skip to content

Instantly share code, notes, and snippets.

@dmamills
Created December 12, 2013 21:23
Show Gist options
  • Save dmamills/7935701 to your computer and use it in GitHub Desktop.
Save dmamills/7935701 to your computer and use it in GitHub Desktop.
var crypto = require('crypto'),
http = require('http'),
qs = require('querystring'),
fs = require('fs'),
path = require('path'),
through = require('through'),
markdown = require('markdown').markdown,
util = require('util');
var server = http.createServer(function(req,res) {
console.log(req.method + ' : ' + req.url);
if(req.method =='GET') {
if(req.url === '/') {
res.end('no root.\n');
} else {
if(path.extname(req.url) === '.md') {
fs.exists(__dirname +'/' + req.url,function(exists) {
if(exists) {
var s = fs.createReadStream(__dirname + '/' + req.url);
s.pipe(through(function(buf) {
this.queue(markdown.toHTML(buf.toString()));
})).pipe(res);
s.on('end',function() { console.log('end..\n'); });
} else {
res.end('dont have that file\n');
}
});
} else {
res.end('MARKDOWN ONLY.\n');
}
}
} else {
//UPLOAD A FILE?
var body = '';
req.on('data',function(data) {
body += data;
})
req.on('end',function(){
var x = qs.parse(body);
res.end(x.lol +'\n');
});
}
});
server.listen('8000');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment