-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
41 lines (35 loc) · 1.21 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
const express = require('express')
const app = express()
const server = require('http').createServer(app)
const io = require('socket.io')(server)
module.exports = io
const passport = require('passport')
const db = require('./models/index')
const userRoutes = require('./routes/UserRoutes')
const teamRoutes = require('./routes/TeamRoutes')
const authRoutes = require('./routes/authRoutes')
const errorHandler = require('./middleware/errorHandler')
const nonExistingRoute = require('./middleware/nonExistingRoute')
const path = require('path')
require('dotenv').config()
const PORT = process.env.PORT || 3000
app.set('view engine', 'ejs')
app.use(express.urlencoded({ extended: true }))
app.use(passport.initialize())
app.use('uploads/', express.static(path.join(__dirname, 'uploads')))
app.use(express.static(path.join(__dirname, 'static')))
app.use(express.json())
app.use(userRoutes)
app.use(teamRoutes)
app.use(authRoutes)
app.use(errorHandler)
app.use(nonExistingRoute)
db.sequelize.sync()
.then(() => console.log('PostgreSQL is synced!'))
.catch(err => console.log(err))
if (process.env.NODE_ENV !== 'test') {
server.listen(PORT, () => {
console.log(`Server started on ${PORT}`)
});
}
module.exports = server