Load frontend configuration at container startup

This commit is contained in:
achraf
2026-06-07 16:32:23 +02:00
parent 0b2d38ee5e
commit 796fa7bb4b
10 changed files with 133 additions and 33 deletions

View File

@@ -0,0 +1,37 @@
export interface PlimiRuntimeConfig {
VITE_PLIMI_REPO_URL?: string;
VITE_SITE_URL?: string;
VITE_LEGAL_NAME?: string;
VITE_LEGAL_COUNTRY?: string;
VITE_PRIVACY_EMAIL?: string;
VITE_PRIVACY_EFFECTIVE_DATE?: string;
VITE_ANALYTICS_PROVIDER_NAME?: string;
VITE_ANALYTICS_SCRIPT_URL?: string;
VITE_ANALYTICS_WEBSITE_ID?: string;
VITE_ANALYTICS_HOST?: string;
VITE_ANALYTICS_HOST_COUNTRY?: string;
VITE_ANALYTICS_RETENTION_MONTHS?: string;
}
declare global {
interface Window {
__PLIMI_CONFIG__?: PlimiRuntimeConfig;
}
}
export function runtimeConfigValue(
name: keyof PlimiRuntimeConfig,
fallback: string
): string {
const runtimeValue = window.__PLIMI_CONFIG__?.[name];
if (typeof runtimeValue === "string" && runtimeValue.trim()) {
return runtimeValue.trim();
}
const buildValue = import.meta.env[name];
if (typeof buildValue === "string" && buildValue.trim()) {
return buildValue.trim();
}
return fallback;
}

View File

@@ -1,30 +1,45 @@
function env(name: keyof ImportMetaEnv, fallback: string): string {
const value = import.meta.env[name];
return typeof value === "string" && value.trim() ? value.trim() : fallback;
}
import { runtimeConfigValue } from "../config/runtime-config";
export const privacyConfig = {
siteName: "Plimi",
siteUrl: env("VITE_SITE_URL", window.location.origin),
controllerName: env("VITE_LEGAL_NAME", "Plimi website operator"),
privacyEmail: env("VITE_PRIVACY_EMAIL", "privacy@example.com"),
controllerCountry: env("VITE_LEGAL_COUNTRY", "Not configured"),
policyEffectiveDate: env("VITE_PRIVACY_EFFECTIVE_DATE", "2026-06-07"),
analyticsProvider: env("VITE_ANALYTICS_PROVIDER_NAME", "Umami"),
analyticsScriptUrl: env(
siteUrl: runtimeConfigValue("VITE_SITE_URL", window.location.origin),
controllerName: runtimeConfigValue(
"VITE_LEGAL_NAME",
"Plimi website operator"
),
privacyEmail: runtimeConfigValue(
"VITE_PRIVACY_EMAIL",
"privacy@example.com"
),
controllerCountry: runtimeConfigValue(
"VITE_LEGAL_COUNTRY",
"Not configured"
),
policyEffectiveDate: runtimeConfigValue(
"VITE_PRIVACY_EFFECTIVE_DATE",
"2026-06-07"
),
analyticsProvider: runtimeConfigValue(
"VITE_ANALYTICS_PROVIDER_NAME",
"Umami"
),
analyticsScriptUrl: runtimeConfigValue(
"VITE_ANALYTICS_SCRIPT_URL",
"https://u.achraf.app/script.js"
),
analyticsWebsiteId: env(
analyticsWebsiteId: runtimeConfigValue(
"VITE_ANALYTICS_WEBSITE_ID",
"89d0f8d2-5b59-438c-b1f6-ab2655e97f6e"
),
analyticsHost: env("VITE_ANALYTICS_HOST", "u.achraf.app"),
analyticsHostCountry: env(
analyticsHost: runtimeConfigValue("VITE_ANALYTICS_HOST", "u.achraf.app"),
analyticsHostCountry: runtimeConfigValue(
"VITE_ANALYTICS_HOST_COUNTRY",
"Not configured"
),
analyticsRetentionMonths: env("VITE_ANALYTICS_RETENTION_MONTHS", "13"),
analyticsRetentionMonths: runtimeConfigValue(
"VITE_ANALYTICS_RETENTION_MONTHS",
"13"
),
};
export const hasAnalyticsConfiguration = Boolean(

View File

@@ -1,8 +1,11 @@
import { Link } from "react-router-dom";
import type { ReactNode } from "react";
import { runtimeConfigValue } from "../core/config/runtime-config";
const repoUrl =
import.meta.env.VITE_PLIMI_REPO_URL || "https://github.com/your-org/plimi";
const repoUrl = runtimeConfigValue(
"VITE_PLIMI_REPO_URL",
"https://github.com/your-org/plimi"
);
const steps = [
{