-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
executable file
·47 lines (39 loc) · 1.35 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
const express = require('express');
const path = require('path');
const bodyParser = require('body-parser');
const morgan = require('morgan');
const session = require('express-session');
const passport = require('./app/config/passport');
const RestHelper = require('./app/helpers/rest-helper');
const timeHelper = require('./app/helpers/time-helper');
const userRole = require('./app/config/connect-roles');
require('./app/models/db');
require('./app/config/passport');
const routesAPI = require('./app/routers/index');
const app = express();
app.use(morgan('dev'));
app.use(bodyParser.json({ limit: '1mb' }));
app.use(bodyParser.urlencoded({ limit: '1mb', extended: false }));
app.use(express.static(path.join(__dirname, 'public')));
const expiryDate = timeHelper.getExpiryDate();
app.use(session({
secret: 'minhaufcg',
resave: false,
saveUninitialized: false,
cookie: {
expires: expiryDate
}
}));
app.use(passport.initialize());
app.use(passport.session());
app.use(userRole.middleware());
app.use('/api', routesAPI);
app.get('/', (req, res) => { res.render('index'); });
app.get('*', (req, res) => { res.sendFile(path.join(__dirname, '/public', 'index.html')); });
app.use((err, req, res, next) => {
RestHelper.sendJsonResponse(res, err.status || 500, {
message: err.message,
error: err
})
});
module.exports = app;