-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
39 lines (35 loc) · 1019 Bytes
/
index.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
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const exphbs = require('express-handlebars');
const pages = require('./pages.js');
const utils = require('./utils.js');
const hbs = exphbs.create({
defaultLayout: 'main',
partialsDir: ['views/partials/']
});
app.engine('handlebars', hbs.engine);
app.set('view engine', 'handlebars');
app.use(bodyParser.urlencoded({
extended: true
}));
app.get('/', function(req, res){
res.render('index', {pages: pages.all});
});
app.route('/:resource/new')
.get(utils.resourceExists, function(req, res){
var data = {
action: 'new',
page: pages.find(req.params.resource)
};
res.render('editor', data);
})
.post(utils.resourceExists, function(req, res){
// handle resource creation
var mdString = utils.createMarkdownString(req.params.resource, req.body);
res.send(mdString);
});
var port = process.env.PORT || 80;
app.listen(port, function () {
console.log('App listening on port '+port+'!');
});