-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
48 lines (34 loc) · 1012 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
42
43
44
45
46
47
48
require('dotenv-safe').config({ path: '.env' })
const bodyParser = require('body-parser')
const express = require('express')
const http = require('http')
const db = require("./src/models/index")
const passportConfig = require('./src/config/passport-config')
const routes = require('./src/routes')
const app = express()
const server = http.Server(app)
app.set('port', (process.env.PORT || 3000))
app.use(bodyParser.json());
const start = async () => {
try {
await db.sync({ force: false })
// initialize passport authentication
passportConfig(app)
// create routes
routes(app)
// deploy
if (process.env.NODE_ENV !== 'test') {
server.listen(app.get('port'), function () {
console.log(`Server started in ${app.settings.env} mode: http://localhost:${app.get('port')}/`)
})
}
return app
} catch (err) {
console.log(err)
process.exitCode = 1
if (err) {
throw err
}
}
}
module.exports = start()