-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
78 lines (61 loc) · 1.74 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
const flash = require('express-flash')
const exphbs = require('express-handlebars')
const express = require('express')
const session = require('express-session')
const FileStore = require('session-file-store')(session)
const conn = require('./db/conn')
const app = express()
// models
const Idea = require('./models/Idea')
const User = require('./models/User')
// import rourtes
const ideasRoutes = require('./routes/ideasRoutes')
const authRoutes = require('./routes/authRoutes')
// Import Controller
const IdeaController = require('./controllers/IdeaController')
// Templete engine
app.engine('handlebars', exphbs())
app.set('view engine', 'handlebars')
// receber resposta do bory
app.use(
express.urlencoded({
extended: true
})
)
//receber dado em json
app.use(express.json())
//session middleware , onde express vai salvar a sessoes
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 message
app.use(flash())
// arquivo publicos
app.use(express.static('public'))
// configurar a sesseion para res
app.use((request, response, next) => {
if(request.session.userid){
response.locals.session = request.session }
next()
})
//Routes
app.use('/ideas', ideasRoutes)
app.use('/', authRoutes)
app.get('/', IdeaController.showIdeas)
conn.sync().then(() => app.listen(3000)
).catch((Error) => console.log(Error))