-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp.js
More file actions
59 lines (32 loc) · 1.05 KB
/
app.js
File metadata and controls
59 lines (32 loc) · 1.05 KB
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
require('dotenv').config();
const express = require('express');
const app = express();
const routes = require('./configs/routes.config');
const bodyParser = require('body-parser');
const setViewLocals = require('./middlewares/setViewLocals');
//configs
require('./configs/hbs.config');
require('./configs/db.config');
app.set('view engine', 'hbs');
app.use(express.static(__dirname + '/public'));
app.set('views', `${__dirname}/views`);
// MIDDELWARES
app.use(bodyParser.urlencoded({ extended: true }));
// SESSION MIDDLEWARES
const {session, loadUserSession} = require('./configs/session.config') // Coge el solo el atributo session del objeto session.config
app.use(session);
app.use(loadUserSession);
app.use((req, res, next) => {
res.locals.lang = req.session.lang || "EN";
next();
});
app.use((req, res, next) => {
res.locals.currentPath = req.path;
res.locals.query = req.query;
next();
});
app.use(setViewLocals);
// APP ROUTES
app.use('/', routes);
const port = 3000;
app.listen(port, () => console.log('App running at port 3000'));