-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
36 lines (28 loc) · 1010 Bytes
/
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
const app = require('express')()
const http = require('http').Server(app)
const bodyParser = require('body-parser')
const db = require('./db/DBService')
const Config = require('./config.json')
const mountRoutes = require('./routes')
const port = process.env.PORT || Config.PORT
console.log('[SERVER] - Launching...')
app.use(bodyParser.json({ limit: '50mb' })) // Support JSON-encoded bodies
app.use(bodyParser.urlencoded({ extended: true, limit: '50mb' })) // Support URL-encoded bodies
// Init DB for entire app
this.initDB = async () => {
try {
await db.initDB()
/* Defines express routes */
mountRoutes(app)
/* HTTP SERVER */
http.listen(port, () => {
console.log('[SERVER] - Launched & ready')
console.log('[SERVER] - PORT: %d', port)
console.log('[SERVER] - PID: %d', process.pid)
})
} catch (err) {
console.error('Failed to init DB')
console.error(err)
}
}
this.initDB()