From 84f227abcf288b28da39ba8035683638a16f13af Mon Sep 17 00:00:00 2001 From: Paul Fitzpatrick Date: Tue, 9 Jul 2024 16:00:58 -0400 Subject: [PATCH] updated at 2024-07-09T16:00:58-04:00 --- core | 2 +- .../lib/configureSendGridNotifier.ts | 8 +++++++- ext/app/server/lib/globalConfig.ts | 19 +++++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 ext/app/server/lib/globalConfig.ts diff --git a/core b/core index 0cdfeeb..8b52d55 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit 0cdfeeb99230480c906781220a71e530540f9b70 +Subproject commit 8b52d55a132f5db0fb453e5bbafac9b684ee0110 diff --git a/ext/app/gen-server/lib/configureSendGridNotifier.ts b/ext/app/gen-server/lib/configureSendGridNotifier.ts index b9e39bb..b8c769f 100644 --- a/ext/app/gen-server/lib/configureSendGridNotifier.ts +++ b/ext/app/gen-server/lib/configureSendGridNotifier.ts @@ -43,13 +43,19 @@ export const SENDGRID_CONFIG: SendGridConfig = { export function configureSendGridNotifier(dbManager: HomeDBManager, gristConfig: GristServer) { if (!process.env.SENDGRID_API_KEY) { return undefined; } + /* TODO: this naughty cast is because settings is of type + * IGristCoreConfig which doesn't have a sendgrid property. Need to + * properly fix this later. + */ + const settings = gristConfig.settings as any; + /* Settings are populated from config.json (located in GRIST_INST_DIR). * * TODO: FlexServer's type for `settings` is an object with unknown values. We should * take advantage of ts-interface-checker to make sure config.json has the right shape * when read at runtime, instead of unsafely asserting here. */ - const sendgridConfig = gristConfig.settings?.sendgrid as SendGridConfig|undefined; + const sendgridConfig = settings?.sendgrid as SendGridConfig|undefined; if (!sendgridConfig) { return undefined; } return new Notifier(dbManager, gristConfig, sendgridConfig); diff --git a/ext/app/server/lib/globalConfig.ts b/ext/app/server/lib/globalConfig.ts new file mode 100644 index 0000000..0c62d85 --- /dev/null +++ b/ext/app/server/lib/globalConfig.ts @@ -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 { + if (!cachedGlobalConfig) { + log.info(`Loading config file from ${globalConfigPath}`); + cachedGlobalConfig = await loadGristCoreConfigFile(globalConfigPath); + } + + return cachedGlobalConfig; +}