-
Notifications
You must be signed in to change notification settings - Fork 48
/
app.js
44 lines (34 loc) · 957 Bytes
/
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
const express = require('express');
const handlebars = require('express-handlebars');
const utils = require('./utils');
const md = require('markdown-it')();
const app = express();
const port = process.env.PORT || 3000;
const handleBars = handlebars.create({
layoutsDir: __dirname + '/views/layouts',
extname: 'hbs',
defaultLayout: 'index',
partialsDir: __dirname + '/views/partials/',
});
app.engine('hbs', handleBars.engine);
app.set('view engine', 'hbs');
app.use(express.static('public'));
app.get('/', (req, res) => {
const readme = md.render(utils.getReadme());
res.render('main', {
...utils.getNavAttributes(),
readme
});
});
app.get('/:route', (req, res) => {
res.render('piece', {
...utils.getNavAttributes(),
scriptName: `${req.params.route}.js`
});
});
app.get('*', (req, res) => {
res.status(404).send('Not found');
});
app.listen(port, () => {
console.log(`Server running on port ${port}`);
});