-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
44 lines (31 loc) · 1.28 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
const express = require('express')
const app = express()
const passport = require('passport')
const morgan = require('morgan')
const cookieParser = require('cookie-parser')
const bodyParser = require('body-parser')
const session = require('express-session')
require('dotenv').config()
const serverPort = require('./server/config/config').serverPort
const sessionSecret = require('./server/config/config').jwtSecret
const cookieSettings = require('./server/config/config').cookieSettings
const port = process.env.PORT || serverPort
const errorHandlingMiddleware = require('./server/middleware/error')
app.use(morgan('dev'))
app.use(cookieParser())
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))
app.use(session({ secret: sessionSecret, cookie: cookieSettings }))
app.use(express.static('./server/static/'))
app.use(express.static('./client/dist/'))
require('./server/passport/passport')(passport)
app.use(passport.initialize())
app.use(passport.session())
const authRoutes = require('./server/routes/auth')
app.use('/auth', authRoutes)
const apiRoutes = require('./server/routes/api')
app.use('/api', apiRoutes)
app.use(errorHandlingMiddleware())
app.listen(port, () => {
console.log('The magic happens on port ' + port)
})