This repository has been archived by the owner on Apr 5, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
53 lines (48 loc) · 1.21 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
53
global.Promise = require('bluebird')
require('dotenv').config()
const requireEnv = require('require-environment-variables')
requireEnv(
['LOG_LEVEL',
'PORT',
'ENCRYPTION_KEY',
'SESSION_KEY',
'SESSION_NAME',
'SESSION_DOMAIN',
'SITE_HOST',
'DB_HOST',
'DB_PORT',
'DB_USER',
'DB_NAME',
'DB_CONNECTION_LIMIT'
])
const logger = require('pino')(
{
name: 'banmanager-api',
level: process.env.LOG_LEVEL
})
const createApp = require('./app')
const setupPool = require('./data/connections/setup-db-pool')
const setupServersPool = require('./data/connections/servers-pool')
const port = process.env.PORT
const dbConfig =
{
connectionLimit: process.env.DB_CONNECTION_LIMIT,
host: process.env.DB_HOST,
port: process.env.DB_PORT,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
multipleStatements: false
}
;(async () => {
try {
const dbPool = await setupPool(dbConfig)
const serversPool = await setupServersPool(dbPool, logger)
const app = await createApp(dbPool, logger, serversPool)
app.listen(port)
logger.info(`Listening on ${port}`)
} catch (error) {
logger.error(error)
process.exit(1)
}
})()