forked from jacksingleton/hacker-slides
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
68 lines (55 loc) · 1.58 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const express = require('express');
const bodyParser = require('body-parser');
const fs = require('fs');
const debug = require('debug')('app');
const dir = __dirname;
const app = express();
const port = 8001;
const editorPath = `${dir}/views/reveal-editor.html`;
const revealPath = `${dir}/data/reveal.html`;
const slidesPath = `${dir}/data/slides.md`;
const imagesPath = `${dir}/data/images`;
app.use(bodyParser.text());
try {
fs.statSync(revealPath);
} catch (err) {
fs.copyFileSync(`${dir}/views/reveal.html`, revealPath);
debug('file reveal.html copied to: %s', revealPath);
}
try {
fs.statSync(slidesPath);
} catch (err) {
fs.copyFileSync(`${dir}/views/slides.md`, slidesPath);
debug('file slides.md copied to: %s', slidesPath);
}
try {
fs.statSync(imagesPath);
} catch (err) {
fs.mkdirSync(imagesPath);
debug('directory images created: %s', imagesPath);
}
debug('revealPath: %s ', revealPath);
debug('slidesPath: %s ', slidesPath);
app.get('/', function (req, res) {
debug('GET /');
res.sendFile(editorPath);
});
app.get('/reveal.html', function (req, res) {
debug('GET /reveal.html');
res.sendFile(revealPath);
});
app.put('/slides.md', function (req, res) {
debug('PUT /slides.md');
fs.writeFile(slidesPath, req.body, function (err) {
if (err) throw err;
res.sendFile(editorPath);
});
});
app.get('/slides.md', function (req, res) {
debug('GET /slides.md');
res.sendFile(slidesPath);
});
app.use(express.static('.'));
app.listen(port, function () {
console.log('Listening on http://127.0.0.1:' + port);
});