-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
56 lines (49 loc) · 1.68 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
require('dotenv').config()
const express = require('express')
const mongoose = require('mongoose')
const passport = require('passport')
const logger = require('morgan')
const bodyParser = require('body-parser')
const session = require('express-session')
const path = require('path')
const expressJWT = require('express-jwt')
const twitterController = require('./controllers/twitterController')
const localPassport = require('./config/passport')
const loginRoutes = require('./config/routes/loginRoutes')
const socialRoutes = require('./config/routes/socialRoutes')
const dashboardRoutes = require('./config/routes/dashboardRoutes')
const port = process.env.PORT || 3000
const mongoUri = process.env.MONGODB_URI || 'mongodb://localhost:27017/smartboard'
const app = express()
const server = require('http').createServer(app)
mongoose.connect(mongoUri)
server.listen(port)
const io = require('socket.io')(server)
if (app.get('env') === 'development') {
require('dotenv').config()
app.use(function (err, req, res, next) {
res.status(err.status || 500)
res.json({
message: err.message,
error: err
})
})
}
app.use(logger('dev'))
app.use(bodyParser())
app.use('/dashboard', expressJWT({
secret: process.env.JWTSECRET
}).unless({path: ['/dashboard']}))
app.use(session({secret: process.env.SESSIONSECRET}))
app.use(passport.initialize())
localPassport(passport)
app.use(express.static('./public'))
app.use('/auth', socialRoutes)
app.use('/dashboard', dashboardRoutes)
app.use('/', loginRoutes)
app.get('*', function (request, response) {
response.sendFile(path.resolve(__dirname, 'public', 'index.html'))
})
io.on('connect', (socket) => {
twitterController.twitterStream(socket)
})