-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
37 lines (31 loc) · 1.03 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
var fs = require('fs')
var path = require('path')
var express = require('express')
var app = express()
var PORT = 9009
var revealPath = path.join(__dirname, 'lib', 'reveal.js')
var presentation = fs.readFileSync(path.join(revealPath, 'index.html'), 'utf-8')
// Integration hack: change resources base path
presentation = presentation.replace('<head>', '<head>\n<base href="../">')
app.use('/talks', express.static(revealPath))
app.use('/talks', express.static(path.join(__dirname, 'talks')))
app.use(function (req, res, next) {
var updatedPath
if (!path.extname(req.url) && req.url.indexOf('?') === -1) {
updatedPath = req.url.replace(/\/*$/, '/');
if (updatedPath !== req.url) {
res.status(301).redirect(updatedPath)
return
}
}
next()
})
app.get(/.*\.md$/, function (req, res, next) {
res.send(404)
})
app.get('/talks/:talk', function (req, res, next) {
res.set('Content-type', 'text/html')
res.send(presentation.replace('presentation.md', req.params.talk + '.md'))
})
app.listen(PORT)
console.log('Server started at', PORT)