-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Working on the home route first, we want to inject all of the seeded …
…posts into the page, so next we will work on the template
- Loading branch information
Christian Martinez
committed
Jul 25, 2023
1 parent
8091526
commit cc6900d
Showing
5 changed files
with
67 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
const router = require('express').Router() | ||
const { Post, User, Comment } = require('../models') | ||
|
||
router.get('/', (req, res) => { | ||
console.log(req.session) | ||
Post.findAll({ | ||
attributes: ['id', 'post_text', 'title', 'created_at'], | ||
order: [['created_at', 'DESC']], | ||
include: [ | ||
{ | ||
model: User, | ||
attributes: ['full_name'], | ||
}, | ||
{ | ||
model: Comment, | ||
attributes: ['id', 'comment_text', 'post_id', 'user_id', 'created_at'], | ||
include: { | ||
model: User, | ||
attributes: ['full_name'], | ||
}, | ||
}, | ||
], | ||
}) | ||
.then((posts) => { | ||
const allPosts = posts.map((post) => post.get({ plain: true })) | ||
res.render('home', { | ||
allPosts, | ||
logged_in: req.session.logged_in, | ||
}) | ||
}) | ||
.catch((err) => { | ||
console.log(err) | ||
res.status(500).json(err) | ||
}) | ||
}) | ||
|
||
module.exports = router |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,8 @@ | ||
const router = require('express').Router() | ||
const apiRoutes = require('./api') | ||
const homeRoutes = require('./home-routes.js') | ||
const dashboardRoutes = require('./dashboard-routes.js') | ||
const homeRoutes = require('./home-routes') | ||
//const dashboardRoutes = require('./dashboard-routes') | ||
|
||
router.use('/api', apiRoutes) | ||
router.use('/', homeRoutes) | ||
router.use('/dashboard', dashboardRoutes) | ||
//router.use('/dashboard', dashboardRoutes) | ||
|
||
module.exports = router |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,34 @@ | ||
const path = require('path') | ||
require('dotenv').config() | ||
const express = require('express') | ||
const session = require('express-session') | ||
const routes = require('./controllers') | ||
const expHps = require('express-handlebars') | ||
const path = require('path') | ||
|
||
const sequelize = require('./config/connection') | ||
const exphbs = require('express-handlebars') | ||
const session = require('express-session') | ||
const SequelizeStore = require('connect-session-sequelize')(session.Store) | ||
const helpers = require('./utils/helpers') | ||
|
||
const hbs = exphbs.create({ helpers }) | ||
const app = express() | ||
const PORT = process.env.PORT || 3001 | ||
|
||
const sess = { | ||
secret: 'Super secret secret', | ||
cookie: { maxAge: 7200000 }, | ||
cookie: {}, | ||
resave: false, | ||
saveUninitialized: true, | ||
store: new SequelizeStore({ | ||
db: sequelize, | ||
}), | ||
} | ||
const app = express() | ||
const PORT = process.env.PORT || 3001 | ||
|
||
app.use(express.static(path.join(__dirname, 'public'))) | ||
|
||
const hbs = expHps.create() | ||
app.engine('handlebars', hbs.engine) | ||
app.set('view engine', 'handlebars') | ||
|
||
app.use(session(sess)) | ||
app.use(express.json()) | ||
app.use(express.urlencoded({ extended: true })) | ||
|
||
app.use(session(sess)) | ||
|
||
app.use(express.static(path.join(__dirname, 'public'))) | ||
app.use(routes) | ||
|
||
sequelize.sync({ force: false }).then(() => { | ||
app.listen(PORT, () => console.log(`Server listening on port ${PORT}`)) | ||
app.listen(PORT, () => console.log(`App listening on port ${PORT}...`)) | ||
}) |