mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
Extracts config.json into its own module (#1061)
This adds a config file that's loaded very early on during startup. It enables us to save/load settings from within Grist's admin panel, that affect the startup of the FlexServer. The config file loading: - Is type-safe, - Validates the config file on startup - Provides a path to upgrade to future versions. It should be extensible from other versions of Grist (such as desktop), by overriding `getGlobalConfig` in stubs. ---- Some minor refactors needed to occur to make this possible. This includes: - Extracting config loading into its own module (out of FlexServer). - Cleaning up the `loadConfig` function in FlexServer into `loadLoginSystem` (which is what its main purpose was before).
This commit is contained in:
19
stubs/app/server/lib/globalConfig.ts
Normal file
19
stubs/app/server/lib/globalConfig.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import path from "path";
|
||||
import { getInstanceRoot } from "app/server/lib/places";
|
||||
import { IGristCoreConfig, loadGristCoreConfigFile } from "app/server/lib/configCore";
|
||||
import log from "app/server/lib/log";
|
||||
|
||||
const globalConfigPath: string = path.join(getInstanceRoot(), 'config.json');
|
||||
let cachedGlobalConfig: IGristCoreConfig | undefined = undefined;
|
||||
|
||||
/**
|
||||
* Retrieves the cached grist config, or loads it from the default global path.
|
||||
*/
|
||||
export async function getGlobalConfig(): Promise<IGristCoreConfig> {
|
||||
if (!cachedGlobalConfig) {
|
||||
log.info(`Loading config file from ${globalConfigPath}`);
|
||||
cachedGlobalConfig = await loadGristCoreConfigFile(globalConfigPath);
|
||||
}
|
||||
|
||||
return cachedGlobalConfig;
|
||||
}
|
||||
Reference in New Issue
Block a user