aboutsummaryrefslogtreecommitdiff
path: root/routes
diff options
context:
space:
mode:
Diffstat (limited to 'routes')
-rw-r--r--routes/web.js17
1 files changed, 12 insertions, 5 deletions
diff --git a/routes/web.js b/routes/web.js
index a1a7b01..49b9b85 100644
--- a/routes/web.js
+++ b/routes/web.js
@@ -1,10 +1,14 @@
const express = require('express');
const router = express.Router();
+const Post = require('../models/post');
router.get('/', (req, res) => {
- res.render('home', {
- title: 'Home Page',
- home: true
+ Post.find().lean().exec((err, posts) => {
+ res.render('home', {
+ title: 'Home Page',
+ home: true,
+ posts: posts
+ });
});
});
@@ -16,8 +20,11 @@ router.get('/new-post', (req, res) => {
});
router.post('/new-post', (req, res) => {
- console.log(req.body);
- res.redirect('/');
+ const newPost = new Post({
+ 'title': req.body.title,
+ 'text': req.body.text
+ });
+ newPost.save().then(() => res.redirect('/'));
});
module.exports = router;