-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
111 lines (103 loc) · 3.47 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import express from "express";
import favicon from "express-favicon";
import { join } from "path";
import { dirname } from "path";
import { fileURLToPath } from "url";
import myRoutes from "./routers/index_routers.js";
import session from "express-session";
import user_session from "./middleware/user_session.js";
import logger from "./logger/index.js";
import "dotenv/config.js";
import cookieParser from "cookie-parser";
import passport from "passport";
import passportFunctionGithub from "./middleware/passport_github.js";
import passportFunctionYandex from "./middleware/passport_yandex.js";
import passportFunctionGoogle from "./middleware/passport_google.js";
import passportFunctionJWT from "./middleware/passport_jwt.js";
// import passportFunctionVK from "./middleware/passport_vkontakte.js";
// import sequelize from "./models/db2.js";
const __dirname = dirname(fileURLToPath(import.meta.url));
const app = express();
const port = process.env.PORT;
const currentTime = new Date().toLocaleString();
app.set("view engine", "ejs");
app.set("\views", __dirname + "views");
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(express.static(join(__dirname, "public")));
app.use(
"/bootstrap.css",
express.static(
join(__dirname, "public/css/bootstrap-5.3.2/dist/css/bootstrap.css")
)
);
app.use("publics", express.static(join(__dirname, "public/")));
app.use(
"/bootstrap.js",
express.static(
join(__dirname, "public/css/bootstrap-5.3.2/dist/js/bootstrap.js")
)
);
app.use(
session({
secret: process.env.SECRET,
resave: false,
saveUninitialized: true,
})
);
app.use(favicon(join(__dirname, "/public/img/Fox(ElectroNic).ico")));
app.use(user_session);
app.use(cookieParser());
app.use(passport.initialize());
app.use(passport.session());
passportFunctionGithub(passport);
passportFunctionJWT(passport);
passportFunctionYandex(passport);
passportFunctionGoogle(passport);
passportFunctionVK(passport);
app.use(myRoutes); // У-y-У-y-У-y-У-y-У-y-У-y-У-y-У-y-У-y-У-y-У-y-У-y-У-y-У-y-У-y-У-y-У-y-У-y-У-y-У-у
app.listen(port, () => {
async () => await sequelize.sync({ foce: true });
console.log("...");
console.log("Проверка console.log пройдена");
console.log("...");
console.log("Начинается логгирование");
console.log("...");
// addline("server started");
console.log("Логгирование завершено");
console.log("...");
console.log("В данный момент используется версия " + app.get("env"));
console.log("...");
logger.info("Запуск сервера");
});
// error handler
app.use((req, res, next) => {
const err = new Error("Какая-то непонятная ошибка");
err.status = 404;
next(err);
});
//production error handler
app.get("env") == "production";
console.log("переход на " + app.get("env"));
if (app.get("env") != "development") {
app.use((err, req, res, next) => {
// err.status = 400;
res.render("error.ejs", { error: err.message, status: err.status });
logger.error(err.message);
});
} else {
app.use((err, req, res, next) => {
res.status = 404;
console.log("! ! !");
console.log("! ! !");
console.log("! ! !");
console.log("ошибка " + res.status);
console.log("! ! !");
console.log(app.get);
console.log("! ! !");
console.log(err.message);
console.log("! ! !");
logger.error(err.message);
res.end("ПЛОХОЙ КОД!");
});
}