diff --git a/docusaurus.config.ts b/docusaurus.config.ts index 5f67a14..e1d0827 100644 --- a/docusaurus.config.ts +++ b/docusaurus.config.ts @@ -2,6 +2,7 @@ import "dotenv/config"; import type { Config } from "@docusaurus/types"; import type { VFile } from "vfile"; +import { getFromSecretOrEnv } from "./utils/general"; import { loadConfig } from "./server/config-docs"; import { getDocusaurusConfigVersionOptions, @@ -26,14 +27,11 @@ const latestVersion = getLatestVersion(); const config: Config = { customFields: { - inkeepConfig: (() => { - const configVars = process.env.secrets ? JSON.parse(process.env.secrets) : process.env; - return { - apiKey: configVars.INKEEP_API_KEY, - integrationId: configVars.INKEEP_INTEGRATION_ID, - organizationId: configVars.INKEEP_ORGANIZATION_ID, + inkeepConfig: { + apiKey: getFromSecretOrEnv("INKEEP_API_KEY"), + integrationId: getFromSecretOrEnv("INKEEP_INTEGRATION_ID"), + organizationId: getFromSecretOrEnv("INKEEP_ORGANIZATION_ID"), } - })(), }, clientModules: [ "./src/styles/variables.css", diff --git a/server/youtube-meta.ts b/server/youtube-meta.ts index 72e95cd..84e9e07 100644 --- a/server/youtube-meta.ts +++ b/server/youtube-meta.ts @@ -2,7 +2,9 @@ * Gets YouTube video metadate given video ID. */ -const YOUTUBE_API_KEY = process.env.YOUTUBE_API_KEY; +import { getFromSecretOrEnv } from "../utils/general"; + +const YOUTUBE_API_KEY = getFromSecretOrEnv("YOUTUBE_API_KEY"); const REQUEST_PATH = "videos"; const YOUTUBE_URL = "https://www.youtube.com/watch"; diff --git a/utils/general.ts b/utils/general.ts index 85652b8..5c707ed 100644 --- a/utils/general.ts +++ b/utils/general.ts @@ -51,3 +51,9 @@ export const filterTextForXSS = (text: string): string => { } return text; }; + +export const getFromSecretOrEnv = (name: string): string => { + // https://docs.aws.amazon.com/amplify/latest/userguide/environment-secrets.html#access-environment-secrets + const configVars = process.env.secrets ? JSON.parse(process.env.secrets) : process.env; + return configVars[name] +};