diff --git a/src/errors/ConfigSchemaError.js b/src/errors/ConfigSchemaError.js new file mode 100644 index 0000000000000000000000000000000000000000..f7ef6604a353a349cd8f64d8a2f498176451c7cf --- /dev/null +++ b/src/errors/ConfigSchemaError.js @@ -0,0 +1,10 @@ +class ConfigSchemaError extends Error { + constructor(message) { + super(message) + + this.name = 'ConfigSchemaError' + this.message = `${message}` + } +} + +module.exports = ConfigSchemaError diff --git a/src/startServer.js b/src/startServer.js index 06964e8de28036082e47d006d401bc3029c3825d..d556ad42d1be2c116962da0dada4bbb49a40b346 100644 --- a/src/startServer.js +++ b/src/startServer.js @@ -13,6 +13,7 @@ const { migrate } = require('./dbManager/migrate') const seedGlobalTeams = require('./startup/seedGlobalTeams') const ensureTempFolderExists = require('./startup/ensureTempFolderExists') const { runCustomStartupScripts } = require('./startup/customScripts') +const checkConfig = require('./startup/checkConfig') let server @@ -23,6 +24,7 @@ const startServer = async (app = express()) => { logInit('Coko server init tasks') + checkConfig() await ensureTempFolderExists() await migrate() await seedGlobalTeams() diff --git a/src/startup/checkConfig.js b/src/startup/checkConfig.js new file mode 100644 index 0000000000000000000000000000000000000000..cae2a0644949f161598aac171bae83f7754cd945 --- /dev/null +++ b/src/startup/checkConfig.js @@ -0,0 +1,19 @@ +const config = require('config') + +const { logTask } = require('../logger/internals') +const ConfigSchemaError = require('../errors/ConfigSchemaError') + +const throwPubsweetKeyError = key => { + throw new ConfigSchemaError( + `The "${key}" key has been removed. Move all configuration that existed under "${key}" to the top level of your config.`, + ) +} + +const check = () => { + logTask('Checking configuration') + + if (config.has('pubsweet')) throwPubsweetKeyError('pubsweet') + if (config.has('pubsweet-server')) throwPubsweetKeyError('pubsweet=server') +} + +module.exports = check