summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2025-12-04 11:01:06 +0100
committerRory& <root@rory.gay>2025-12-04 11:01:18 +0100
commit4047c52f2d8aa8f1ffceb65fe7c2bbc5b2513412 (patch)
treea4fa55d6abc2c6932e74a82e703d5f04da7c9613 /src
parentRemove fallback URIs, remove endpointClient, expose admin api (diff)
downloadserver-ts-4047c52f2d8aa8f1ffceb65fe7c2bbc5b2513412.tar.xz
validate that endpoitns are configured
Diffstat (limited to 'src')
-rw-r--r--src/util/util/Config.ts39
1 files changed, 38 insertions, 1 deletions
diff --git a/src/util/util/Config.ts b/src/util/util/Config.ts

index 2fd9c0fb..a79c908d 100644 --- a/src/util/util/Config.ts +++ b/src/util/util/Config.ts
@@ -54,7 +54,9 @@ export class Config { config = OrmUtils.mergeDeep({}, { ...new ConfigValue() }, config); - return this.set(config); + await this.set(config); + validateFinalConfig(config); + return config; }; public static get() { if (!config) { @@ -169,3 +171,38 @@ const validateConfig = async () => { return config; }; + +function validateFinalConfig(config: ConfigValue) { + let hasErrors = false; + function assertConfig(path: string, condition: (val: any) => boolean, recommendedValue: string) { + // _ to separate keys + const keys = path.split("_"); + let obj: any = config; + + for (const key of keys) { + if (obj == null || !(key in obj)) { + console.warn(`[Config] Missing config value for '${path}'. Recommended value: ${recommendedValue}`); + return; + } + obj = obj[key]; + } + + if (!condition(obj)) { + console.warn(`[Config] Invalid config value for '${path}': ${obj}. Recommended value: ${recommendedValue}`); + hasErrors = true; + } + } + + assertConfig("api_endpointPublic", v => v != null, "A valid public API endpoint URL, ex. \"http://localhost:3001/api/v9\""); + assertConfig("cdn_endpointPublic", v => v != null, "A valid public CDN endpoint URL, ex. \"http://localhost:3002/\""); + assertConfig("cdn_endpointPrivate", v => v != null, "A valid private CDN endpoint URL, ex. \"http://localhost:3002/\" - must be routable from the API server!"); + assertConfig("gateway_endpointPublic", v => v != null, "A valid public gateway endpoint URL, ex. \"ws://localhost:3003/\""); + + if (hasErrors) { + console.error( + "[Config] Your config has invalid values. Fix them first https://docs.spacebar.chat/setup/server/configuration", + ); + console.error("[Config] Hint: if you're just testing with bundle (`npm run start`), you can set all endpoint URLs to [proto]://localhost:3001"); + process.exit(1); + } else console.log("[Config] Configuration validated successfully."); +} \ No newline at end of file