From 88bc820dfb15a558677e8fa4663c6c4f720f3aee Mon Sep 17 00:00:00 2001 From: Ariel Weinberger Date: Sun, 16 Nov 2025 23:12:36 -0600 Subject: [PATCH] dybnamic env --- docker/generate-env.sh | 23 ++++++++++++++++++----- src/lib/profiles/index.svelte.ts | 4 ++-- src/lib/studio/studio-widget.ts | 5 ++--- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/docker/generate-env.sh b/docker/generate-env.sh index ac83a5781..e39881fb6 100755 --- a/docker/generate-env.sh +++ b/docker/generate-env.sh @@ -62,11 +62,6 @@ else fi echo "Writing to: $env_file" - -# Remove old compressed versions FIRST (nginx might serve these instead) -rm -f "${env_file}.br" "${env_file}.gz" -echo " Removed old compressed files" - echo "export const env=$env_json" > "$env_file" # Verify the file was written @@ -79,6 +74,24 @@ echo "✓ Successfully generated $env_file" echo "File contents:" cat "$env_file" +# NUKE all pre-compressed files so nginx serves fresh content +echo "Nuking all .br and .gz files..." +find /usr/share/nginx/html/console -type f \( -name "*.br" -o -name "*.gz" \) -delete +echo "✓ Nuked all compressed files" + +# Replace hardcoded PUBLIC_ values in JavaScript files +# Vite inlines env vars at build time, so we need to replace them in the built JS +echo "Replacing hardcoded env values in JavaScript files..." +for var in $public_vars; do + value=$(printenv "$var") + echo " Replacing $var in JS files..." + + # Find all .js files and replace the value + # Match pattern: "PUBLIC_VAR":"old_value" or 'PUBLIC_VAR':'old_value' + find /usr/share/nginx/html/console -type f -name "*.js" -exec sed -i "s|\"$var\":\"[^\"]*\"|\"$var\":\"$value\"|g" {} \; +done +echo "✓ Replaced env values in JS files" + echo "=========================================" echo "Starting nginx..." echo "=========================================" diff --git a/src/lib/profiles/index.svelte.ts b/src/lib/profiles/index.svelte.ts index a8d94562d..bcdb8284b 100644 --- a/src/lib/profiles/index.svelte.ts +++ b/src/lib/profiles/index.svelte.ts @@ -1,6 +1,6 @@ import { asset, resolve } from '$app/paths'; import type { ResolvedPathname } from '$app/types'; -import { PUBLIC_CONSOLE_PROFILE } from '$env/static/public'; +import { env } from '$env/dynamic/public'; export const enum ProfileMode { STUDIO = 'studio', @@ -114,7 +114,7 @@ export const studio: Profile = { }; const resolver = $derived(() => { - switch (PUBLIC_CONSOLE_PROFILE) { + switch (env.PUBLIC_CONSOLE_PROFILE) { case 'studio': return studio; default: diff --git a/src/lib/studio/studio-widget.ts b/src/lib/studio/studio-widget.ts index 6ea27537e..055014ddc 100644 --- a/src/lib/studio/studio-widget.ts +++ b/src/lib/studio/studio-widget.ts @@ -1,4 +1,3 @@ -import { PUBLIC_APPWRITE_ENDPOINT, PUBLIC_AI_SERVICE_BASE_URL } from '$env/static/public'; import { env } from '$env/dynamic/public'; import { app } from '$lib/stores/app'; import { get } from 'svelte/store'; @@ -283,8 +282,8 @@ export async function initImagine( if (!configInitialized) { initImagineConfig( { - AI_SERVICE_ENDPOINT: PUBLIC_AI_SERVICE_BASE_URL, - APPWRITE_ENDPOINT: PUBLIC_APPWRITE_ENDPOINT, + AI_SERVICE_ENDPOINT: env.PUBLIC_AI_SERVICE_BASE_URL, + APPWRITE_ENDPOINT: env.PUBLIC_APPWRITE_ENDPOINT, APPWRITE_SITES_BASE_URL: '' }, {