Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

feat: added runtime env config endpoint

=d0648ca596ca
diff --git a/backend/src/lib/config/env.ts b/backend/src/lib/config/env.ts
index 7b6f356fd7..599fa1f960 100644
--- a/backend/src/lib/config/env.ts
+++ b/backend/src/lib/config/env.ts
@@ -157,6 +157,8 @@ const envSchema = z
INFISICAL_CLOUD: zodStrBool.default("false"),
MAINTENANCE_MODE: zodStrBool.default("false"),
CAPTCHA_SECRET: zpStr(z.string().optional()),
+ CAPTCHA_SITE_KEY: zpStr(z.string().optional()),
+ INTERCOM_ID: zpStr(z.string().optional()),
// TELEMETRY
OTEL_TELEMETRY_COLLECTION_ENABLED: zodStrBool.default("false"),
diff --git a/backend/src/server/app.ts b/backend/src/server/app.ts
index 6405306ab0..d001d900e7 100644
--- a/backend/src/server/app.ts
+++ b/backend/src/server/app.ts
@@ -120,12 +120,10 @@ export const main = async ({ db, hsmModule, auditLogDb, smtp, logger, queue, key
await server.register(registerRoutes, { smtp, queue, db, auditLogDb, keyStore, hsmModule });
- if (appCfg.isProductionMode) {
- await server.register(registerServeUI, {
- standaloneMode: appCfg.STANDALONE_MODE || IS_PACKAGED,
- dir: path.join(__dirname, IS_PACKAGED ? "../../../" : "../../")
- });
- }
+ await server.register(registerServeUI, {
+ standaloneMode: appCfg.STANDALONE_MODE || IS_PACKAGED,
+ dir: path.join(__dirname, IS_PACKAGED ? "../../../" : "../../")
+ });
await server.ready();
server.swagger();
diff --git a/backend/src/server/plugins/serve-ui.ts b/backend/src/server/plugins/serve-ui.ts
index 1616347581..1cda2fbd5e 100644
--- a/backend/src/server/plugins/serve-ui.ts
+++ b/backend/src/server/plugins/serve-ui.ts
@@ -2,7 +2,7 @@ import path from "node:path";
import staticServe from "@fastify/static";
-import { IS_PACKAGED } from "@app/lib/config/env";
+import { getConfig, IS_PACKAGED } from "@app/lib/config/env";
// to enabled this u need to set standalone mode to true
export const registerServeUI = async (
@@ -15,6 +15,26 @@ export const registerServeUI = async (
dir: string;
}
) => {
+ // use this only for frontend runtime static non-sensitive configuration in standalone mode
+ // that app needs before loading like posthog dsn key
+ // for most of the other usecase use server config
+ server.route({
+ method: "GET",
+ url: "/runtime-ui-env.js",
+ handler: (_req, res) => {
+ const appCfg = getConfig();
+ void res.type("application/javascript");
+ const config = {
+ CAPTCHA_SITE_KEY: appCfg.CAPTCHA_SITE_KEY,
+ POSTHOG_API_KEY: appCfg.POSTHOG_PROJECT_API_KEY,
+ INTERCOM_ID: appCfg.INTERCOM_ID,
+ TELEMETRY_CAPTURING_ENABLED: appCfg.TELEMETRY_ENABLED
+ };
+ const js = `window.__INFISICAL_RUNTIME_ENV__ = Object.freeze(${JSON.stringify(config)});`;
+ void res.send(js);
+ }
+ });
+
if (standaloneMode) {
const frontendName = IS_PACKAGED ? "frontend" : "frontend-build";
const frontendPath = path.join(dir, frontendName);