-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
72 lines (52 loc) · 1.88 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
const express = require("express");
const path = require("path");
const logger = require("morgan");
const app = express();
const models = require("./database/models");
const config = require("./config/config.js");
const favicon = require("serve-favicon");
app.use(logger("dev"));
///////////////////////////////////////////
const webPush = require("web-push");
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
//app.use(express.static(path.join(__dirname, 'public')));
app.use(express.static("public"));
app.use(express.static("node_modules"))
app.use(favicon(path.join(config.imgDir, "favicon.ico")));
//push
webPush.setVapidDetails(
"mailto:[email protected]",
process.env.PUBLIC_VAPID_KEY,
process.env.PRIVATE_VAPID_KEY
);
//!push
const { initAuthControllers } = require("./routes/index.js");
const { loadPasportStrategies } = require("./controllers/users/users");
const session = require("express-session");
const passport = require("passport");
app.use(
session({ secret: config.secretKey, resave: true, saveUninitialized: true })
); // session secret
app.use(passport.initialize()); //возможно, нужно чистить сессии
app.use(passport.session()); // persistent login sessions
initAuthControllers(app, passport);
loadPasportStrategies(passport, models.user)
async function start() {
try {
await models.sequelize.sync()
console.log("Nice! Database looks fine");
} catch(err) {
console.log("Something went wrong with the Database Update!");
console.log("Crashed with error: "+ err)
return; // сервер не стартанул
}
try {
await app.listen(config.port)
console.log("Server started on " + config.port + " port");
} catch(err) {
console.error("Server not started");
}
}
start().catch(console.error)
module.exports = app