-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
72 lines (63 loc) · 1.99 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
64
65
66
67
68
69
70
71
72
require('dotenv').config();
//const http = require('http');
const express = require('express');
const bodyParser = require('body-parser');
const path = require('path');
//Mongoose
const mongoose = require('mongoose');
const session = require('express-session');
const MongoDBStore = require('connect-mongodb-session')(session);
//URI de mongo
const MongoDB_URI =
'mongodb+srv://SMS_nodeApp:[email protected]/test?retryWrites=true&w=majority';
//Initialize express
const app = express();
//Guardar sesiones en MONGODB
const store = new MongoDBStore({
uri: MongoDB_URI,
collection: 'sessions'
});
//Template Engine
app.set('view engine', 'ejs');
app.set('views', 'views');
//Routes functions
const homeRoutes = require('./routes/home');
//const errorRoutes = require('./routes/error');
const authRoutes = require('./routes/auth');
//Ruta para vistas de usuario
const userRoutes = require('./routes/users')
//Middlewares - Encode Body + Static Files
app.use(
bodyParser.urlencoded({
extended: false
})
);
app.use(express.static(path.join(__dirname, 'public')));
//Sesion
app.use(
session({
secret: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.',
resave: false,
saveUninitialized: false,
store: store
})
);
//Routes to home
app.use(homeRoutes);
//Routes to error pages
//app.use(errorRoutes);
//Routes to auth
app.use(authRoutes);
//Rutas vistas de usuario
app.use(userRoutes);
//Server port
const PORT = process.env.PORT || 3000;
//Connect DB
mongoose
.connect(MongoDB_URI)
.then(result => {
app.listen(PORT);
})
.catch(err => {
console.log(err);
});