-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
63 lines (57 loc) · 2.53 KB
/
server.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
require('dotenv').config()
const express = require('express'),
mongoose = require('mongoose'),
passport = require('passport'),
session = require('express-session'),
flash = require('express-flash'),
app = express(),
passportInit = require('./utils/passport-config'),
{ensureAuthenticated, forwardAuthenticated, ensureVerified, ensureKyc} = require('./utils/authenticate'),
PORT = process.env.PORT || 5000
const indexRouter = require('./routers/indexRouter'),
loginRouter = require('./routers/loginRouter'),
regRouter = require('./routers/regRouter'),
reportRouter = require('./routers/reportRouter'),
cropRouter = require('./routers/cropRouter'),
retirementRouter = require('./routers/retirementRouter'),
loyaltyRouter = require('./routers/loyaltyRouter'),
perksRouter = require('./routers/perksRouter'),
jobRouter = require('./routers/jobRouter'),
kycRouter = require('./routers/kycRouter'),
verifyRouter = require('./routers/verifyRouter'),
eventRouter = require('./routers/eventRouter'),
profileRouter = require('./routers/profileRouter')
app.use(express.static('public'))
app.set('view engine', 'ejs')
app.use(express.json())
app.use(express.urlencoded({extended: false}))
passportInit(passport)
app.use(flash())
app.use(session({
secret: process.env.SESSION_SECRET,
resave: true,
saveUninitialized: true
}))
app.use(passport.initialize())
app.use(passport.session())
mongoose.connect(process.env.MONGO_URI, console.log('MONGODB CONNECTED'))
app.use('/', indexRouter)
app.use('/login', forwardAuthenticated, loginRouter)
app.use('/register', forwardAuthenticated, regRouter)
app.use('/report', ensureAuthenticated, ensureKyc, ensureVerified, reportRouter)
app.use('/crop', ensureAuthenticated, ensureKyc, ensureVerified, cropRouter)
app.use('/level', ensureAuthenticated, ensureKyc, ensureVerified, loyaltyRouter)
app.use('/retirement', ensureAuthenticated, ensureKyc, ensureVerified, retirementRouter)
app.use('/perks', ensureAuthenticated, ensureKyc, ensureVerified, perksRouter)
app.use('/job', ensureAuthenticated, ensureKyc, ensureVerified, jobRouter)
app.use('/kyc', ensureAuthenticated, kycRouter)
app.use('/verify', ensureAuthenticated, ensureKyc, verifyRouter)
app.use('/profile', ensureAuthenticated, profileRouter)
app.use('/events', ensureAuthenticated, eventRouter)
app.get('/logout', (req, res) => {
req.logout((err) => {
if (err) console.log(err)
return res.redirect('/login')
});
})
app.listen(PORT, console.log(`Server listening on port ${PORT}`))