Skip to content

Commit

Permalink
updated at 2024-07-09T16:00:58-04:00
Browse files Browse the repository at this point in the history
  • Loading branch information
paulfitz committed Jul 9, 2024
1 parent 9f5e0ee commit 84f227a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion core
Submodule core updated 1 files
+1 −1 README.md
8 changes: 7 additions & 1 deletion ext/app/gen-server/lib/configureSendGridNotifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
19 changes: 19 additions & 0 deletions ext/app/server/lib/globalConfig.ts
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 84f227a

Please sign in to comment.