-
Notifications
You must be signed in to change notification settings - Fork 6
/
app.js
64 lines (52 loc) · 1.78 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
const config = require('./config')
const express = require('express')
const morgan = require('morgan')
const bodyParser = require('body-parser')
const passport = require('passport')
const LocalStrategy = require('passport-local').Strategy
const User = require('./models/user.model')
const logger = require('./utils/logger')
const auth_route = require('./routes/auth.route')
const admin_route = require('./routes/admin.route')
const message_route = require('./routes/message.route')
const db = require('./db/db')
const socket = require('socket.io')
const mongoose = require('mongoose')
const session = require('express-session')
const MongoStore = require('connect-mongo')(session)
const app = express()
app.set('view engine', 'ejs')
app.use(express.static('public'))
app.use(express.static('media'))
app.use(bodyParser.json({limit: "5mb"}))
app.use(bodyParser.urlencoded({ limit: "5mb", extended: false }))
if (process.env.NODE_ENV !== 'test') {
app.use(morgan("dev"))
}
db.init()
app.use(session({
secret: 'Silicon Valley',
resave: false,
saveUninitialized: false,
store: new MongoStore({ mongooseConnection: mongoose.connection })
}))
app.use(passport.initialize())
app.use(passport.session())
passport.use(new LocalStrategy(User.authenticate()))
passport.serializeUser(User.serializeUser())
passport.deserializeUser(User.deserializeUser())
app.use(auth_route)
app.use('/admin', admin_route)
app.use('/message', message_route.router)
app.use('/threads',message_route.router)
app.get('/server-status', (req, res) => {
res.status(200).send('Server is up!')
})
// start the server
const server = app.listen(config.port, '0.0.0.0', () => {
logger.info(`munverse started on ${config.port}`)
})
var io = socket(server)
message_route.io(io)
// expose to the test suite
module.exports = app