-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
56 lines (49 loc) · 1.42 KB
/
index.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
54
55
56
const Promise = require('bluebird')
const express = require('express')
const { MongoClient } = require('mongodb')
const winston = require('winston')
const { main } = require('./lib/main')
const app = express()
const logger = winston.createLogger({
level: process.env.LOG_LEVEL || 'debug',
format: winston.format.json(),
defaultMeta: { service: 'server' },
transports: [
new winston.transports.Console()
]
})
const port = process.env.PORT || 3000
const mongoUri = process.env.MONGO_URI || 'mongodb://localhost:27018/fll-cloud'
const mongoPromise = MongoClient.connect(mongoUri, {
promiseLibrary: Promise,
useNewUrlParser: true
})
const config = {
auth: {
google: {
clientId: process.env.GOOGLE_CONSUMER_KEY,
clientSecret: process.env.GOOGLE_CONSUMER_SECRET
},
callbackBaseUrl: process.env.AUTH_CALLBACK_BASE_URL,
superAdminEmail: process.env.SUPER_AMDIN_EMAIL
},
appSecret: process.env.APP_SECRET || 'secret'
}
const options = {
app,
db: mongoPromise.then(client => client.db()),
config,
logger,
mongo: mongoPromise
}
const entries = Object.entries(options)
Promise.all(entries.map(([k, v]) => v))
.then(optionsArray => main(entries
.map(([k], index) => ({ [k]: optionsArray[index] }))
.reduce((obj, entry) => Object.assign(obj, entry), {})))
.then(() => app.listen(port, () => {
logger.info(`Server listens in port ${port}`)
}))
.catch(err => {
throw err
})