This repository has been archived by the owner on Dec 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfiguration.js
107 lines (101 loc) · 3.02 KB
/
configuration.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
const MongoDBRepositoryFactory = require('./MongoDBRepositoryFactory')
const { MongoClient } = require('mongodb')
const axios = require('axios')
const log4js = require('log4js')
function requiredEnv (key) {
const value = process.env[key]
if (!value) throw new Error(`Required environment variable: ${key}`)
return value
}
exports.config = {
'config:legacyUser:apiKey': {
create: () => requiredEnv('LEGACY_USER_API_KEY')
},
'config:mongodb:url': {
create: () => {
const DEFAULT_MONGO_URL = 'mongodb://127.0.0.1:27017/bemuse'
return process.env.MONGO_URL || process.env.MONGODB_URI || DEFAULT_MONGO_URL
}
},
'config:jwt:certificateUrl': {
create: () => requiredEnv('JWT_CERTIFICATE_URL')
},
'config:playerToken:secret': {
create: () => requiredEnv('PLAYER_TOKEN_SECRET')
}
}
exports.logger = {
'logger:http': {
create: () => log4js.getLogger('http')
}
}
exports.authentication = {
'authentication:jwt:certificate': {
create: ({ certificateUrl }) => (
axios.get(certificateUrl).then(response => response.data)
),
dependencies: { certificateUrl: 'config:jwt:certificateUrl' }
},
'authentication:userTokenValidator': {
create: require('./createTokenValidator'),
dependencies: { certificate: 'authentication:jwt:certificate' }
},
'authentication:playerTokenService': {
create: require('./createPlayerTokenService'),
dependencies: { secret: 'config:playerToken:secret' }
}
}
exports.database = {
'database:mongodb': {
create: ({ url }) => MongoClient.connect(url),
dependencies: {
url: 'config:mongodb:url'
}
}
}
exports.repository = {
'repository:factory': {
create: ({ db }) => new MongoDBRepositoryFactory({ db }),
dependencies: { db: 'database:mongodb' }
},
'repository:legacyUser': {
create: ({ factory }) => factory.createLegacyUserRepository(),
dependencies: { factory: 'repository:factory' }
},
'repository:rankingEntry': {
create: ({ factory }) => factory.createRankingEntryRepository(),
dependencies: { factory: 'repository:factory' }
},
'repository:player': {
create: ({ factory }) => factory.createPlayerRepository(),
dependencies: { factory: 'repository:factory' }
}
}
exports.api = {
'api:legacyUserApi': {
create: require('./createLegacyUserApi'),
dependencies: {
legacyUserApiKey: 'config:legacyUser:apiKey',
legacyUserRepository: 'repository:legacyUser',
playerRepository: 'repository:player'
}
},
'api:graphql:root': {
create: require('./createRoot'),
dependencies: {
rankingEntryRepository: 'repository:rankingEntry',
legacyUserRepository: 'repository:legacyUser',
playerRepository: 'repository:player',
userTokenValidator: 'authentication:userTokenValidator',
playerTokenService: 'authentication:playerTokenService'
}
},
'api:app': {
create: require('./createApiServer'),
dependencies: {
logger: 'logger:http',
legacyUserApi: 'api:legacyUserApi',
graphqlRoot: 'api:graphql:root'
}
}
}