-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
79 lines (62 loc) · 1.76 KB
/
index.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const express = require('express')
const exphbs = require('express-handlebars')
const session = require('express-session')
const FileStore = require('session-file-store')(session)
const flash = require('express-flash')
const app = express()
const conn = require('./db/conn')
app.engine('handlebars', exphbs.engine())
app.set('view engine', 'handlebars')
app.use(express.urlencoded({
extended: true
}))
app.use(express.json())
app.use(express.static('public'))
// Models
const User = require('./models/User')
const Thoughts = require('./models/Thoughts')
// Rotes
const thoughtsRoutes = require('./routes/thoughtsRoutes')
const authRoutes = require('./routes/authRoutes')
// Controllers
const ThoughtsController = require('./controllers/ThoughtsController')
// session middleware
app.use(
session({
name: 'session',
secret: 'nosso_secret',
resave: false,
saveUninitialized: false,
store: new FileStore({
logFn: function () { },
path: require('path').join(require('os').tmpdir(), 'sessions')
}),
cookie: {
secure: false,
maxAge: 360000,
expires: new Date(Date.now() + 360000),
httpOnly: true,
}
}),
)
// flash messages
app.use(flash())
//set session to res
app.use((req, res, next) => {
if (req.session.userid) {
res.locals.session = req.session;
}
next();
});
app.use('/thoughts', thoughtsRoutes)
app.use('/', authRoutes)
app.get('/', ThoughtsController.showThoughts)
conn
.sync()
//.sync({ force: true })
.then(() => {
app.listen(3000, () => {
console.log('Conectado a porta http://localhost:3000')
})
})
.catch((err) => { console.log('erro na conexão => ', err) })