enforce config on backend

This commit is contained in:
Ulf Gebhardt 2022-03-18 03:13:00 +01:00
parent c6cd6f37e6
commit 677581b76e
Signed by: ulfgebhardt
GPG Key ID: DA6B843E748679C9
3 changed files with 21 additions and 0 deletions

View File

@ -1,3 +1,5 @@
CONFIG_VERSION=v1.2022-03-18
# Server
PORT=4000
JWT_SECRET=secret123

View File

@ -1,3 +1,5 @@
CONFIG_VERSION=$BACKEND_CONFIG_VERSION
# Server
JWT_SECRET=$JWT_SECRET
JWT_EXPIRES_IN=10m

View File

@ -12,6 +12,11 @@ Decimal.set({
const constants = {
DB_VERSION: '0032-add-transaction-link-to-transaction',
DECAY_START_TIME: new Date('2021-05-13 17:46:31'), // GMT+0
CONFIG_VERSION: {
DEFAULT: 'DEFAULT',
EXPECTED: 'v1.2022-03-18',
CURRENT: '',
},
}
const server = {
@ -78,6 +83,18 @@ const webhook = {
// This is needed by graphql-directive-auth
process.env.APP_SECRET = server.JWT_SECRET
// Check config version
constants.CONFIG_VERSION.CURRENT = process.env.CONFIG_VERSION || constants.CONFIG_VERSION.DEFAULT
if (
![constants.CONFIG_VERSION.EXPECTED, constants.CONFIG_VERSION.DEFAULT].includes(
constants.CONFIG_VERSION.CURRENT,
)
) {
throw new Error(
`Fatal: Config Version incorrect - expected "${constants.CONFIG_VERSION.EXPECTED}" or "${constants.CONFIG_VERSION.DEFAULT}", but found "${constants.CONFIG_VERSION.CURRENT}"`,
)
}
const CONFIG = {
...constants,
...server,