aboutsummaryrefslogtreecommitdiff
path: root/routes
diff options
context:
space:
mode:
authorMateja <mail@matejamaric.com>2021-05-03 15:34:46 +0200
committerMateja <mail@matejamaric.com>2021-05-03 15:34:46 +0200
commit9eeca255cfe41ca4a962422c3703274caa530021 (patch)
tree2353081cf1e2b75535eb4e5c65e418bb3f12cf90 /routes
parent3460f9ad874495469cfa8d4aaa42b66f5e427bf2 (diff)
downloadnode-playground-9eeca255cfe41ca4a962422c3703274caa530021.tar.gz
node-playground-9eeca255cfe41ca4a962422c3703274caa530021.zip
Started using controllers.
Diffstat (limited to 'routes')
-rw-r--r--routes/web.js29
1 files changed, 4 insertions, 25 deletions
diff --git a/routes/web.js b/routes/web.js
index 49b9b85..732c87c 100644
--- a/routes/web.js
+++ b/routes/web.js
@@ -1,30 +1,9 @@
const express = require('express');
const router = express.Router();
-const Post = require('../models/post');
+const postController = require('../controllers/post');
-router.get('/', (req, res) => {
- Post.find().lean().exec((err, posts) => {
- res.render('home', {
- title: 'Home Page',
- home: true,
- posts: posts
- });
- });
-});
-
-router.get('/new-post', (req, res) => {
- res.render('new-post', {
- title: 'Make A New Post',
- newPost: true
- });
-});
-
-router.post('/new-post', (req, res) => {
- const newPost = new Post({
- 'title': req.body.title,
- 'text': req.body.text
- });
- newPost.save().then(() => res.redirect('/'));
-});
+router.get('/', postController.index);
+router.get('/new-post', postController.create);
+router.post('/new-post', postController.store);
module.exports = router;