-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
120 lines (78 loc) · 2.73 KB
/
index.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
112
113
114
115
116
117
118
119
120
const express = require('express');
const app= express();
const port = 8000;
const Mongostore = require('connect-mongo');
const { connect, set } = require('mongoose');
const path = require('path');
const db = require('./config/mongoose');
const flash = require('connect-flash');
const customMware = require('./config/middleware');
const cookieParser = require('cookie-parser');
const nodemailer = require('nodemailer');
const session = require('express-session');
const Contests = require('./models/Contests');
const axios = require('axios');
const passport = require('passport');
const JWTPassport = require('./config/passport-jwt');
const passportLocal = require('./config/passport-local-strategy');
const passportGoogle = require('./config/passport-google-auth2-Strategy');
const passportGithub = require('./config/passport-github2-Strategy');
const {allContests} = require('./controllers/Pagecontroller.js');
const fixtime = require('./config/fixedtimemailer');
const variabletime = require('./config/timebeforecontest');
const expressLayouts = require('express-ejs-layouts');
const config = require("./config/config.js");
app.use(express.urlencoded({extended:true}));
app.use(cookieParser());
app.use(expressLayouts);
app.set('layout extractStyles', true);
app.set('layout extractScripts', true);
app.set('view engine','ejs');
app.set('views','./views');
app.use(session({
name:'Harshitcookie',
secret:config.session_cookie_secret_key,
saveUninitialized:false,
resave:false,
cookie:{
maxAge:(1000 * 60 * 100)
// }
},
store: Mongostore.create({
mongoUrl :"mongodb://127.0.0.1:27017/mydatabase",
autoRemove:'disabled'
})
}))
app.use(passport.initialize());
app.use(passport.session());
app.use(passport.setAuthenticatedUser);
app.use(flash());
app.use(customMware.setFlash);
const cron = require('node-cron');
cron.schedule('0 0 * * *',async () => {
await allContests();
});
if(config.fixTimeM!=0){
// Check if there are documents and schedule fixtime.mailsender if there are
cron.schedule('*/59 * * * *', async () => {
const count = await Contests.countDocuments();
if (count > 0) {
fixtime.mailsender();
}
});
}
if(config.varTimeM!=0){
// Check if there are documents and schedule variabletime.mailsender if there are
cron.schedule('*/59 * * * *', async () => {
const count = await Contests.countDocuments();
if (count > 0) {
variabletime.mailsender();
}
});
}
app.use(express.static('./assets'));
app.use('/',require('./routes'));
app.listen(port,function(err){
if(err){console.log("error in running port ",port,err);}
console.log(`congratulation ${port} in running successfully`);
})