-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
69 lines (58 loc) · 1.75 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
const express = require('express')
const app = express()
const hbs = require('express-handlebars')
const path = require('path')
const admin = require('./routes/admin')
require('./models/Note')
const dataHora = require('./public/js/datahora')
const mongoose = require('mongoose')
const Note = mongoose.model('notes')
const session = require('express-session')
const flash = require('connect-flash')
const db = require('./config/db')
const usuarios = require('./routes/usuario')
console.log(dataHora)
// Configurações
// Body Parser
app.use(express.json({limit: '20mb'}));
app.use(express.urlencoded({ extended: false, limit: '20mb' }))
// Template Engine
app.engine('hbs', hbs({
defaultLayout: 'main',
extname: '.hbs',
layoutsDir: __dirname + '/views/layouts/',
partialsDir: __dirname + '/views/partials/'
}))
app.set('view engine', 'hbs')
// Public
app.use(express.static(path.join(__dirname, '/public')))
app.use(express.static(path.join(__dirname, '/views')))
// Mongoose
mongoose.connect('mongodb+srv://jesiel364:12458917@jesieldb.twzzt.mongodb.net/todoapp?retryWrites=true&w=majority').then(() => {
console.log('MONGODB Conectado.')
}).catch((err) => {
console.log('Erro ao tentar se conectar ao MONGODB: '+err)
})
// Sessão
app.use(session({
name : 'codeil',
secret : 'something',
resave :false,
saveUninitialized: true,
cookie : {
maxAge:(1000 * 60 * 100)
}}))
app.use(flash())
// Middleware
app.use((req, res, next) => {
res.locals.success_msg = req.flash('success_msg')
res.locals.error_msg = req.flash('error_msg')
next()
})
// Rotas
app.use('/', admin)
app.use('/usuarios', usuarios)
const PORT = process.env.PORT || 8089
app.listen(PORT, ()=> {
console.log('Servidor rodando na porta 8089')
})