text: const router = require('express').Router();
  const { Post, User, Comment } = require('../models');
  
  // shows all posts on the homepage
  router.get('/', (req, res) => {
      console.log(req.session);
  
      Post.findAll({
          attributes: [
              'id',
              'title',
              'content',
              'created_at'
          ],
          include: [
              {
                  model: Comment,
                  attributes: ['id', 'comment_text', 'post_id', 'user_id', 'created_at'],
                  include: {
                      model: User,
                      attributes: ['username']
                  }
              },
              {
                  model: User,
                  attributes: ['username']
              }
          ]
      })
      .then(dbPostData => {
         const posts = dbPostData.map(post => post.get({ plain: true }));
          res.render('homepage', { 
              posts,
              loggedIn: req.session.loggedIn
          });
      })
      .catch(err => {
          console.log(err);
          res.status(500).json(err);
      });
  });
  
  // route for the user to login
  router.get('/login', (req, res) => {
      if (req.session.loggedIn) {
          res.redirect('/');
          return;
      }
      
      res.render('login');
  });
  
  // route for a user to sign up
  router.get('/sign-up', (req, res) => {
      if (req.session.loggedIn) {
          res.redirect('/');
          return;
      }
      
      res.render('sign-up');
  });
  
  // rought to see a single post
  router.get('/post/:id', (req, res) => {
      Post.findOne({
          where: {
              id: req.params.id
          },
          attributes: [
              'id',
              'title',
              'content',
              'created_at'
          ],
          include: [
              {
                  model: Comment,
                  attributes: ['id', 'comment_text', 'post_id', 'user_id', 'created_at'],
                  include: {
                      model: User,
                      attributes: ['username']
                  }
              },
              {
                  model: User,
                  attributes: ['username']
              }
          ]
      })
      .then(dbPostData => {
          if (!dbPostData) {
              res.status(404).json({ message: 'No post found with this id' });
              return;
          }
  
          const post = dbPostData.get({ plain: true });
  
          res.render('single-post', { 
              post,
              loggedIn: req.session.loggedIn
          });
      })
      .catch(err => {
          console.log(err);
          res.status(500).json(err);
      });
  });
  
  module.exports = router;