-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
52 lines (42 loc) · 1.32 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
/* eslint-disable no-console */
console.log('Starting Server......')
// Config
require('dotenv-safe').load() // Load env vars from ./.env
console.log(`NODE_ENV =${process.env.NODE_ENV}`)
const port = process.env.PORT
console.log(`Port = ${port}`)
const express = require('express')
const app = express()
module.exports = app // for testing
// POST Body Parsing:
const bodyParser = require('body-parser')
app.use(bodyParser.json())
// DB:
const { sequelize } = require('./models')
// Session
const expressSession = require('express-session')
const SequelizeStore = require('connect-session-sequelize')(expressSession.Store)
app.use(expressSession({
name: 'winder-session',
secret: 'random_string_goes_here',
duration: 30 * 60 * 1000,
activeDuration: 5 * 60 * 1000,
store: new SequelizeStore({
db: sequelize
}),
proxy: true // using SSL outside of node
}))
// Authentication:
const passport = require('./passportAuthentication')
app.use(passport.initialize())
app.use(passport.session())
// socket.io
var chatServer = require('http').Server(app)
chatServer.listen(process.env.CHAT_PORT, process.env.CHAT_HOST)
var io = require('socket.io')(chatServer, {origins: '*:*'})
require('./io')(app, io)
// Routes:
app.use(express.static('client/build'))
require('./routes')(app, passport, __dirname)
// All set!
app.listen(port)