diff options
author | Arnaud CHESNAY <arnaud.chesnay@etu.univ-nantes.fr> | 2017-09-27 09:06:27 +0200 |
---|---|---|
committer | Arnaud CHESNAY <arnaud.chesnay@etu.univ-nantes.fr> | 2017-09-27 09:06:27 +0200 |
commit | be836b55b4f8bc541b49c392d91954fb855529b8 (patch) | |
tree | 670312eebc189f1e737536c098f47c8c4befd940 /app.js | |
parent | first commit (diff) |
push website
Diffstat (limited to 'app.js')
-rw-r--r-- | app.js | 48 |
1 files changed, 48 insertions, 0 deletions
@@ -0,0 +1,48 @@ +'use-strict'; + +const showdown = require('showdown'); +const dirTree = require('directory-tree'); +const express = require('express'); +const fs = require('fs'); + +const converter = new showdown.Converter(); +const app = express(); +const path = 'md' + +app.use(express.static('public')); + +app.get('/' + path + '/*', function(req, res) { + fs.readFile(req.url.substr(1), 'utf8', function(err, data) { + if (err) + return console.log(err); + fs.readFile('public/css/style.css', 'utf8', function(err, style) { + var html = '<html>'; + html += '<head>'; + html += '<style>' + style + '</style>'; + html += '</head>'; + html += '<body class=\'markdown-preview\' data-use-github-style>'; + html += converter.makeHtml(data); + html += '</body>'; + html += '</html>'; + res.send(html); + }); + }); +}); + +app.get('/data', function(req, res) { + res.send(dirTree(path, {extensions:/\.md/})); +}); + +app.get('/', function(req, res) { + fs.readFile('public/index.html', 'utf8', function(err, data) { + if (err) + return console.log(err); + res.send(data); + }); +}); + +var server = app.listen(8080, function() { + var host = server.address().address; + var port = server.address().port; + console.log("App listening at http://%s:%s", host, port); +}); |