Skip to content

Commit

Permalink
refactor(server): use convict to create configuration
Browse files Browse the repository at this point in the history
Configuration defined by schema and passed as an object

fixes #897
  • Loading branch information
iainsproat committed Aug 29, 2022
1 parent 23bc801 commit 0a631dd
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,8 @@
"commitizen": {
"path": "cz-conventional-changelog"
}
},
"dependencies": {
"convict": "^6.2.3"
}
}
12 changes: 8 additions & 4 deletions packages/server/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ const {
getApolloServerVersion,
getServerVersion
} = require('./modules/shared/helpers/envHelper')

if (isApolloMonitoringEnabled() && !getApolloServerVersion()) {
process.env.APOLLO_SERVER_USER_VERSION = getServerVersion()
}
const convict = require('convict')

// If running in test env, load .env.test first
// (appRoot necessary, cause env files aren't loaded through require() calls)
Expand All @@ -44,7 +41,14 @@ if (isTestEnv()) {

dotenv.config({ path: `${packageRoot}/.env` })

const config = convict('./config.schema.json')

if (isApolloMonitoringEnabled() && !getApolloServerVersion()) {
process.env.APOLLO_SERVER_USER_VERSION = getServerVersion()
}

module.exports = {
config,
appRoot,
packageRoot
}
8 changes: 8 additions & 0 deletions packages/server/config.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"env": {
"doc": "The application environment.",
"format": ["production", "development", "test"],
"default": "development",
"env": "NODE_ENV"
}
}
13 changes: 12 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11724,6 +11724,16 @@ __metadata:
languageName: node
linkType: hard

"convict@npm:^6.2.3":
version: 6.2.3
resolution: "convict@npm:6.2.3"
dependencies:
lodash.clonedeep: ^4.5.0
yargs-parser: ^20.2.7
checksum: 69e44ac26405bf4abcc452a95cf5b9f0ef55786cdf19526a83165e2746a93d86187e3705ebf7e7efc8f06e904143acb228ba21604202ec5a937aed0958d49ac7
languageName: node
linkType: hard

"cookie-parser@npm:~1.4.4":
version: 1.4.6
resolution: "cookie-parser@npm:1.4.6"
Expand Down Expand Up @@ -24677,6 +24687,7 @@ __metadata:
dependencies:
"@types/eslint": ^8.4.1
commitizen: ^4.2.4
convict: ^6.2.3
cz-conventional-changelog: ^3.3.0
eslint: ^8.11.0
eslint-config-prettier: ^8.5.0
Expand Down Expand Up @@ -29458,7 +29469,7 @@ __metadata:
languageName: node
linkType: hard

"yargs-parser@npm:^20.2.2":
"yargs-parser@npm:^20.2.2, yargs-parser@npm:^20.2.7":
version: 20.2.9
resolution: "yargs-parser@npm:20.2.9"
checksum: 8bb69015f2b0ff9e17b2c8e6bfe224ab463dd00ca211eece72a4cd8a906224d2703fb8a326d36fdd0e68701e201b2a60ed7cf81ce0fd9b3799f9fe7745977ae3
Expand Down

0 comments on commit 0a631dd

Please sign in to comment.