Skip to content

Commit eea7aa9

Browse files
committed
Make backend-config.json optional
Configuration values can be provided either from the config file or env variables. Signed-off-by: Mike Lischke <mike@lischke-online.de>
1 parent 2cdf71f commit eea7aa9

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

src/server/config.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
/* eslint-disable no-restricted-syntax */
77

8-
import { readFileSync } from "node:fs";
8+
import { existsSync, readFileSync } from "node:fs";
99
import { resolve } from "node:path";
1010

1111
import { DatabaseEngine, type IDatabaseConfig } from "./database.js";
@@ -27,7 +27,10 @@ export interface IServerConfig {
2727
}
2828

2929
export const loadConfig = (): IServerConfig => {
30-
const raw = JSON.parse(readFileSync(configPath, "utf-8")) as Partial<IServerConfig>;
30+
let raw: Partial<IServerConfig> = {};
31+
if (existsSync(configPath)) {
32+
raw = JSON.parse(readFileSync(configPath, "utf-8")) as Partial<IServerConfig>;
33+
}
3134

3235
// Parse ALLOWED_ORIGINS env var (comma-separated).
3336
const allowedOriginsEnv = process.env.ALLOWED_ORIGINS

0 commit comments

Comments
 (0)