Created
December 12, 2013 21:23
-
-
Save dmamills/7935701 to your computer and use it in GitHub Desktop.
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 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