-
Notifications
You must be signed in to change notification settings - Fork 0
/
instances.js
79 lines (69 loc) · 2.54 KB
/
instances.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
require('dotenv').config();
const RedisDatabase = require('./modules/database/redis');
const SessionManager = require('./modules/manager/session');
const Mongoose = require('./modules/database/mongodb');
const RedisStore = require('connect-redis').default;
const accountSchema = require('./modules/schema/account');
const problemSchema = require('./modules/schema/problem');
const contestSchema = require('./modules/schema/contest');
const profileSchema = require('./modules/schema/profile');
const scoreboardSchema = require('./modules/schema/scoreboard');
const ProblemManager = require('./modules/manager/problem');
const ContestManager = require('./modules/manager/contest');
const AccountManager = require('./modules/manager/account');
const ProfileManager = require('./modules/manager/profile');
const ScoreboardManager = require('./modules/manager/scoreboard');
const TimeManager = require('./modules/manager/time');
const redisSessionDBName = process.env.REDIS_DB_NAME;
const redisSessionDB = new RedisDatabase(redisSessionDBName, {
socket: {
port: process.env.REDIS_PORT,
host: process.env.REDIS_HOST,
connectTimeout: 100000
},
password: process.env.REDIS_PASSWORD,
legacyMode: false,
});
const sessionManager = new SessionManager(redisSessionDB, {
store: new RedisStore({ client: redisSessionDB.client }),
name: process.env.SESSION_NAME,
secret: process.env.SESSION_SECRET,
resave: false,
saveUninitialized: false,
cookie: {
// secure: (process.env.MODE == "dev") ? false : true,
domain: (process.env.MODE == "dev") ? undefined : ".icewall.org",
// httpOnly: true,
// maxAge: 1000 * 60 * 60 * 24,
// sameSite: 'lax'
}
});
const mongoDBURL = process.env.MONGO_DB_URL;
const mongoDBName = process.env.MONGO_DB_NAME;
const mongoDB = new Mongoose(mongoDBName, {
"account": accountSchema,
"problem": problemSchema,
"contest": contestSchema,
"profile": profileSchema,
"scoreboard": scoreboardSchema
}, mongoDBURL);
const accountManager = new AccountManager(mongoDB, "account");
const problemManager = new ProblemManager(mongoDB, "problem");
const contestManager = new ContestManager(mongoDB, "contest");
const profileManager = new ProfileManager(mongoDB, "profile");
const scoreboardManager = new ScoreboardManager(mongoDB, "scoreboard");
const timeManager = new TimeManager();
const run = async () => {
await mongoDB.connect();
await redisSessionDB.connect();
}
module.exports = {
sessionManager,
accountManager,
problemManager,
contestManager,
profileManager,
scoreboardManager,
timeManager,
run
}