-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
51 lines (44 loc) · 1.17 KB
/
server.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
import express from 'express';
import router from "./routes/index.js";
import router2 from "./routes/api.js";
import routeruser from "./routes/user.js";
import routeradmin from "./routes/admin.js";
import db from './config/db.js';
import session from "express-session";
import dotenv from "dotenv";
dotenv.config();
// crear la app
const app = express();
//asignar puerto
const port = process.env.PORT || 4000;
//concectar db
db.authenticate()
.then(() => console.log("conectado a la base de datos"))
.catch(error => console.log(error));
// agregar el pug
app.set("view engine", "pug");
// add bodt parser para datos del form
app.use(express.urlencoded({extended : true}));
//agregar carpeta public
app.use(express.static("public"));
// use sessions
app.use(session({
secret:'session',
resave:false,
saveUninitialized:true,
}));
app.use((req, res, next)=> {
if(req.session.user){
res.locals.user=req.session.user;
}
next();
});
//agregar router
app.use("/", router);
app.use("/api/v1", router2);
app.use("/user/",routeruser);
app.use("/admin",routeradmin);
// empezar servidor
app.listen(port, () => {
console.log(`empezando en el puerto ${port}`);
});