-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
66 lines (52 loc) · 1.56 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
//librerias
const express = require("express");
const { create } = require("express-handlebars");
const session = require("express-session");
const flash = require("connect-flash");
const passport = require("passport");
const csrf = require('csurf');
const path = require('path');
//configuracion de la BD y llamar al archivo db
require("dotenv").config();
require("./database/db");
//Express
const app = express();
app.use(express.json());
app.use(express.urlencoded({extended:true}));
//session
app.use(session({
secret:"cyberwolf",
resave:false,
saveUninitialized:false,
name:"secret-wolf",
}));
//flash
app.use(flash());
//inicializacion de pasport para las sessiones
app.use(passport.initialize());
app.use(passport.session());
app.use(express.static(path.join(__dirname, 'public')));
//configuracion handelbars
const hbs = create({
extname: ".hbs",
partialsDir: ["views/components"],
});
app.engine(".hbs", hbs.engine);
app.set("view engine", ".hbs");
app.set("views", "./views");
// inicializacion de csrf y middleware verificacion csrf
app.use(csrf());
app.use((req,res,next)=>{
res.locals.user = req.user;
res.locals.csrfToken = req.csrfToken();
res.locals.mensaje = req.flash("mensaje");
res.locals.mensajes = req.flash("mensajes");
next();
});
//rutas
app.use("/",require("./routes/auth"));
app.use("/home",require("./routes/home"));
app.use("/profile",require("./routes/profile"));
app.use("/book",require("./routes/book"));
const PORT = process.env.PORT || 5000;
app.listen(PORT, () => console.log("server andando 🔥"));