Skip to content

Commit 88bc820

Browse files
dybnamic env
1 parent 3799b12 commit 88bc820

3 files changed

Lines changed: 22 additions & 10 deletions

File tree

docker/generate-env.sh

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,6 @@ else
6262
fi
6363

6464
echo "Writing to: $env_file"
65-
66-
# Remove old compressed versions FIRST (nginx might serve these instead)
67-
rm -f "${env_file}.br" "${env_file}.gz"
68-
echo " Removed old compressed files"
69-
7065
echo "export const env=$env_json" > "$env_file"
7166

7267
# Verify the file was written
@@ -79,6 +74,24 @@ echo "✓ Successfully generated $env_file"
7974
echo "File contents:"
8075
cat "$env_file"
8176

77+
# NUKE all pre-compressed files so nginx serves fresh content
78+
echo "Nuking all .br and .gz files..."
79+
find /usr/share/nginx/html/console -type f \( -name "*.br" -o -name "*.gz" \) -delete
80+
echo "✓ Nuked all compressed files"
81+
82+
# Replace hardcoded PUBLIC_ values in JavaScript files
83+
# Vite inlines env vars at build time, so we need to replace them in the built JS
84+
echo "Replacing hardcoded env values in JavaScript files..."
85+
for var in $public_vars; do
86+
value=$(printenv "$var")
87+
echo " Replacing $var in JS files..."
88+
89+
# Find all .js files and replace the value
90+
# Match pattern: "PUBLIC_VAR":"old_value" or 'PUBLIC_VAR':'old_value'
91+
find /usr/share/nginx/html/console -type f -name "*.js" -exec sed -i "s|\"$var\":\"[^\"]*\"|\"$var\":\"$value\"|g" {} \;
92+
done
93+
echo "✓ Replaced env values in JS files"
94+
8295
echo "========================================="
8396
echo "Starting nginx..."
8497
echo "========================================="

src/lib/profiles/index.svelte.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { asset, resolve } from '$app/paths';
22
import type { ResolvedPathname } from '$app/types';
3-
import { PUBLIC_CONSOLE_PROFILE } from '$env/static/public';
3+
import { env } from '$env/dynamic/public';
44

55
export const enum ProfileMode {
66
STUDIO = 'studio',
@@ -114,7 +114,7 @@ export const studio: Profile = {
114114
};
115115

116116
const resolver = $derived(() => {
117-
switch (PUBLIC_CONSOLE_PROFILE) {
117+
switch (env.PUBLIC_CONSOLE_PROFILE) {
118118
case 'studio':
119119
return studio;
120120
default:

src/lib/studio/studio-widget.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { PUBLIC_APPWRITE_ENDPOINT, PUBLIC_AI_SERVICE_BASE_URL } from '$env/static/public';
21
import { env } from '$env/dynamic/public';
32
import { app } from '$lib/stores/app';
43
import { get } from 'svelte/store';
@@ -283,8 +282,8 @@ export async function initImagine(
283282
if (!configInitialized) {
284283
initImagineConfig(
285284
{
286-
AI_SERVICE_ENDPOINT: PUBLIC_AI_SERVICE_BASE_URL,
287-
APPWRITE_ENDPOINT: PUBLIC_APPWRITE_ENDPOINT,
285+
AI_SERVICE_ENDPOINT: env.PUBLIC_AI_SERVICE_BASE_URL,
286+
APPWRITE_ENDPOINT: env.PUBLIC_APPWRITE_ENDPOINT,
288287
APPWRITE_SITES_BASE_URL: ''
289288
},
290289
{

0 commit comments

Comments
 (0)