-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
86 lines (74 loc) · 2.14 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
const express = require("express");
const session = require("express-session")
const app = express();
const dotenv = require("dotenv");
dotenv.config();
const port = process.env.APP_PORT;
app.use((session({
secret: "QuasartSession",
resave: false,
saveUninitialized: true,
cookie: { secure: false }
})))
app.use(express.static("app/public"));
app.set("view engine", "ejs");
app.set("views", "./app/views");
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
// ROUTES
var rotas = require("./app/routes/routerHome");
app.use("/", rotas);
var rotasAdm = require("./app/routes/routerAdm");
app.use("/", rotasAdm);
var rotasEditProfile = require("./app/routes/routerEditProfile");
app.use("/", rotasEditProfile);
var rotasConta = require("./app/routes/routerConta");
app.use("/", rotasConta);
app.use("/error-404", (req, res) => {
let token = req.session.token || null;
if (token && token.contagem < 1) {
req.session.token.contagem++;
} else {
req.session.token = null;
}
res.status(404).render("pages/template-home", {
foto: req.session.autenticado ? req.session.autenticado.foto : "perfil-padrao.webp",
page: "../partial/error-404",
classePagina: "",
token: token,
});
});
app.use("/sem-permissao", (req, res) => {
let token = req.session.token || null;
if (token && token.contagem < 1) {
req.session.token.contagem++;
} else {
req.session.token = null;
}
res.render("pages/template-home", {
foto: "perfil-padrao.webp",
page: "../partial/sem-permissao",
classePagina: "",
token: null,
});
});
app.use("/error-500", (req, res) => {
let token = req.session.token || null;
if (token && token.contagem < 1) {
req.session.token.contagem++;
} else {
req.session.token = null;
}
res.status(500).render("pages/template-home", {
foto: req.session.autenticado ? req.session.autenticado.foto : "perfil-padrao.webp",
page: "../partial/error-500",
classePagina: "",
token: token,
});
});
app.use((req, res) => {
res.redirect('/error-404');
});
app.listen(port, () => {
console.log(`Servidor ouvindo na porta ${port}\nhttp://localhost:${port}`);
});