aboutsummaryrefslogtreecommitdiff
path: root/app.js
diff options
context:
space:
mode:
authorArnaud CHESNAY <arnaud.chesnay@etu.univ-nantes.fr>2017-09-27 09:06:27 +0200
committerArnaud CHESNAY <arnaud.chesnay@etu.univ-nantes.fr>2017-09-27 09:06:27 +0200
commitbe836b55b4f8bc541b49c392d91954fb855529b8 (patch)
tree670312eebc189f1e737536c098f47c8c4befd940 /app.js
parentfirst commit (diff)
push website
Diffstat (limited to 'app.js')
-rw-r--r--app.js48
1 files changed, 48 insertions, 0 deletions
diff --git a/app.js b/app.js
new file mode 100644
index 0000000..388b9cb
--- /dev/null
+++ b/app.js
@@ -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);
+});