-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
63 lines (54 loc) · 1.78 KB
/
app.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
const express = require('express')
const settings = require('./config/settings.json')
const handlebars = require('express-handlebars')
const bodyParser = require('body-parser')
const app = express();
const usuarios = require('./routes/usuarios');
const admin = require('./routes/admin');
const {authAdmin} = require('./middleware/userAuthenticated');
const path = require('path')
require('./database')
const session = require('express-session')
const flash = require('connect-flash');
const passport = require('passport');
require('./config/auth')(passport)
// Configurações
// Sessão
app.use(session({
secret: 'helpdeskinfosaude',
resave: true,
saveUninitialized: true,
}));
app.use(passport.initialize())
app.use(passport.session())
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');
res.locals.error = req.flash('error');
res.locals.user = req.user || null;
next()
})
// Body Parser
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
// Handlebars
app.engine('handlebars', handlebars.engine({defaultLayout: 'main'}));
app.set('view engine', 'handlebars');
// Public
app.use(express.static(path.join(__dirname,'public')));
// Rotas
app.get('/', (req, res)=>{
res.render('index')
})
app.use('/usuarios', usuarios)
app.use('/admin', authAdmin,admin)
app.get('*', (req, res) => {
res.render('notfound')
})
// Outros
const PORT = settings.servidor.port
app.listen(PORT,() =>{
console.log('servidor rodando')
});