Skip to content

Commit

Permalink
Throw error when config.json contains invalid JSON or is inaccessible
Browse files Browse the repository at this point in the history
  • Loading branch information
stefandesu committed Mar 5, 2024
1 parent 95e8d60 commit 8242c5a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ npm ci
```

### Configuration
You can customize the application settings via a configuration file. By default, this configuration file resides in `config/config.json`. However, it is possible to adjust this path via the `CONFIG_FILE` environment variable. Note that the given path has to be either absolute (i.e. starting with `/`) or relative to the `config/` folder (i.e. it defaults to `./config.json`). **Note** that the path to the configuration file needs to be valid and writable because a `namespace` key will be generated and written to the file if it doesn't currently exist.
You can customize the application settings via a configuration file. By default, this configuration file resides in `config/config.json`. However, it is possible to adjust this path via the `CONFIG_FILE` environment variable. Note that the given path has to be either absolute (i.e. starting with `/`) or relative to the `config/` folder (i.e. it defaults to `./config.json`). **Note** that the path to the configuration file needs to be valid and writable because a `namespace` key will be generated and written to the file if it doesn't currently exist. **Note** that if the file exists and contains invalid JSON data, JSKOS Server will refuse to start.

Currently, there are only two environment variables:
- `NODE_ENV` - either `development` (default) or `production`; currently, the only difference is that in `production`, HTTPS URIs are forced for entities created on POST requests.
Expand Down
3 changes: 2 additions & 1 deletion config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ let configUser = {}
try {
configUser = JSON.parse(fs.readFileSync(configFilePath))
} catch(error) {
console.warn(`Warning: Could not load configuration file from ${configFilePath}. The application might not behave as expected.`)
console.error(`Warning: Could not load configuration file from ${configFilePath}. Please check whether it is valid JSON and restart the application.`)
process.exit(1)
}
if (env == "test") {
configUser = _.pick(configUser, ["mongo"])
Expand Down

0 comments on commit 8242c5a

Please sign in to comment.