-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
41 lines (32 loc) · 991 Bytes
/
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
const express = require('express')
const path = require('path')
const fs = require('fs')
const passport = require('passport')
const db = require('./server/db')
const setUpRoutes = require('./server/routes')
const setUpExpress = require('./server/config/express')
const setUpPassport = require('./server/config/passport')
const port =
process.env.NODE_ENV != 'production' ? 3000 : process.env.PORT || 8080
const app = express()
// Set up passport
setUpPassport(passport)
app.use(passport.initialize())
// Set up express
setUpExpress(app)
// Set up routes
setUpRoutes(app)
//bootstrap models
const modelDir = path.join(__dirname, 'server', 'models')
fs
.readdirSync(modelDir)
.filter(file => ~file.search(/^[^\.].*\.js$/)) // eslint-disable-line no-useless-escape
.forEach(file => require(path.join(modelDir, file)))
//create tables
db.sync()
/* eslint-disable */
app.listen(port, () => {
console.log(`Server running on port ${port}`)
})
/* eslint-enable */
module.exports = app