-
-
Save jdkanani/b5843f661792456aba20 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 http = require('http'), | |
fs = require('fs'), | |
path = require('path'), | |
exec = require('child_process').exec; | |
function pipeDoc(inputPath, finalType, stream) { | |
var finalPath = path.dirname(inputPath) | |
+ "/" + path.basename(inputPath).split('.')[0] + ".html"; | |
var convCommand = 'unoconv -f ' + finalType + " " + inputPath; | |
exec(convCommand,function(err, stdout, stderr) { | |
process.stdout.write(stdout); | |
fs.createReadStream(finalPath).pipe(stream); | |
}); | |
} | |
http.createServer(function(rq, rs) { | |
rs.writeHead(200, {'Content-Type': 'text/html'}); | |
var rqPath = rq.url; | |
if (path.extname(rqPath).length > 1) { | |
pipeDoc(rq.url, "html", rs); | |
} | |
else { | |
rs.end( | |
"<html><body><h1>Use the url http://localhost:8080/path_to_document to view in browser</h1></body></html>" | |
); | |
} | |
}).listen(8080); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment