MCPcopy Create free account
hub / github.com/lightdash/lightdash / parseConfig

Function parseConfig

packages/backend/src/config/parseConfig.ts:2074–2838  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2072];
2073
2074export const parseConfig = (): LightdashConfig => {
2075 const lightdashSecret = process.env.LIGHTDASH_SECRET;
2076 if (!lightdashSecret) {
2077 throw new ParseError(
2078 `Must specify environment variable LIGHTDASH_SECRET. Keep this value hidden!`,
2079 {},
2080 );
2081 }
2082 const lightdashMode = process.env.LIGHTDASH_MODE;
2083 if (lightdashMode !== undefined && !isLightdashMode(lightdashMode)) {
2084 throw new ParseError(
2085 `Lightdash mode set by environment variable LIGHTDASH_MODE=${lightdashMode} is invalid. Must be one of ${Object.values(
2086 LightdashMode,
2087 )}`,
2088 {},
2089 );
2090 }
2091
2092 const mode = lightdashMode || LightdashMode.DEFAULT;
2093
2094 const siteUrl = process.env.SITE_URL || 'http://localhost:8080';
2095 if (
2096 process.env.NODE_ENV !== 'development' &&
2097 siteUrl.includes('localhost')
2098 ) {
2099 console.log(
2100 `WARNING: Using ${siteUrl} as the base SITE_URL for Lightdash. This is not suitable for production. Update with a top-level domain using https such as https://lightdash.mycompany.com`,
2101 );
2102 }
2103
2104 const iframeAllowedDomains = getArrayFromCommaSeparatedList(
2105 'LIGHTDASH_IFRAME_EMBEDDING_DOMAINS',
2106 );
2107 const corsAllowedDomains = getArrayFromCommaSeparatedList(
2108 'LIGHTDASH_CORS_ALLOWED_DOMAINS',
2109 );
2110 const iframeEmbeddingEnabled = iframeAllowedDomains.length > 0;
2111 const corsEnabled = process.env.LIGHTDASH_CORS_ENABLED !== 'false';
2112 const secureCookies = process.env.SECURE_COOKIES === 'true';
2113 const useSecureBrowser = process.env.USE_SECURE_BROWSER === 'true';
2114 const browserProtocol = useSecureBrowser ? 'wss' : 'ws';
2115 const browserEndpoint = useSecureBrowser
2116 ? `${browserProtocol}://${process.env.HEADLESS_BROWSER_HOST}`
2117 : `${browserProtocol}://${process.env.HEADLESS_BROWSER_HOST}:${process.env.HEADLESS_BROWSER_PORT}`;
2118
2119 if (iframeEmbeddingEnabled && !secureCookies) {
2120 throw new ParameterError(
2121 'To enable iframe embedding, SECURE_COOKIES must be set to true',
2122 );
2123 }
2124
2125 const rawCopilotConfig = getAiConfig();
2126 const copilotConfigParse =
2127 aiCopilotConfigSchema.safeParse(rawCopilotConfig);
2128
2129 let copilotConfig: AiCopilotConfigSchemaType;
2130 if (!copilotConfigParse.success) {
2131 copilotConfig = rawCopilotConfig as AiCopilotConfigSchemaType;

Callers 3

setupIntegrationTestFunction · 0.90
lightdashConfig.tsFile · 0.90

Tested by

no test coverage detected