-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
59 lines (57 loc) · 1.77 KB
/
server.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
require('dotenv').config()
const express=require('express')
const app=express()
const layouts=require('express-ejs-layouts')
const axios=require('axios')
const methodOverride=require('method-override')
app.use(express.static(__dirname + '/public'))
const session = require('express-session')
const passport = require('./config/ppConfig.js')
const flash = require('connect-flash')
const db=require('./models')
// define view engine. view engine help us to render the page. Ejs helps user to use html and java script
app.set('view engine','ejs')
// layout midle ware
app.use(layouts)
// session midleware
app.use(session({
secret: process.env.SESSION_SECRET,
resave: false,
saveUninitialized: true
}))
// passport midleware
app.use(passport.initialize())
app.use(passport.session())
// flash middleware
app.use(flash())
// CUSTOM MIDDLEWARE
app.use((req, res, next)=>{
// before every route, attach teh flash messages and current user to res.locals
res.locals.alerts = req.flash()
res.locals.currentUser = req.user
next() // move on to the next piece of middleware
})
// midelware to pars body
app.use(express.urlencoded({extended:false}))
// method override midleware
app.use(methodOverride('_method'))
// routes midle ware
app.use('/movies',require('./routes/movie.js'))
app.use('/profile',require('./routes/profile.js'))
// Get Home route
app.get('/',(req,res)=>{
// db.user.findAll().then(info=>{
// console.log("😒")
// console.log(info)
// info.forEach(user=>{
// user.getMovies().then(movie=>{
// console.log("😁")
// console.log(movie)
// })
// })
// })
res.render('home.ejs')
})
app.listen(process.env.PORT,()=>{
console.log(`👌I'm listening to ${process.env.PORT}`)
})