From 2e2e65a9f4b4bf56136dff75945de27d9443310f Mon Sep 17 00:00:00 2001 From: mahdahar <89adham@gmail.com> Date: Thu, 19 Feb 2026 16:34:29 +0700 Subject: [PATCH] feat: Add environment-specific config management - Remove static/config.json from git tracking - Add .env.example and config.json.example as templates - Update config store to fallback to VITE_API_URL env variable - Add build.sh script for dev/prod builds --- .env.example | 2 ++ .gitignore | 2 +- build.sh | 24 +++++++++++++++++++++ src/lib/stores/config.js | 24 +++++++++++++++------ static/{config.json => config.json.example} | 0 5 files changed, 44 insertions(+), 8 deletions(-) create mode 100644 .env.example create mode 100644 build.sh rename static/{config.json => config.json.example} (100%) diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..6511bcf --- /dev/null +++ b/.env.example @@ -0,0 +1,2 @@ +# Copy this file to .env.local for local development +VITE_API_URL=http://localhost/clqms01 diff --git a/.gitignore b/.gitignore index a6d5d44..fb4965f 100644 --- a/.gitignore +++ b/.gitignore @@ -23,4 +23,4 @@ vite.config.js.timestamp-* vite.config.ts.timestamp-* /.claude -/.serena \ No newline at end of file +/.serenastatic/config.json diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..ba99d83 --- /dev/null +++ b/build.sh @@ -0,0 +1,24 @@ +#!/bin/bash +# Build script for different environments + +# Usage: ./build.sh [dev|prod] + +ENV=${1:-dev} + +case $ENV in + dev) + echo "Building for development..." + cp static/config.json.dev static/config.json 2>/dev/null || echo "Using env variable VITE_API_URL" + vite build + ;; + prod) + echo "Building for production..." + # Production uses env variable, no config.json needed + rm -f static/config.json + vite build + ;; + *) + echo "Usage: ./build.sh [dev|prod]" + exit 1 + ;; +esac diff --git a/src/lib/stores/config.js b/src/lib/stores/config.js index 9aa0ef7..7b78bd9 100644 --- a/src/lib/stores/config.js +++ b/src/lib/stores/config.js @@ -15,7 +15,7 @@ function createConfigStore() { subscribe, /** - * Load configuration from config.json + * Load configuration from config.json or env variables */ load: async () => { if (!browser) return; @@ -32,12 +32,22 @@ function createConfigStore() { error: null, }); } catch (err) { - console.error('Failed to load config:', err); - set({ - apiUrl: '', - loaded: true, - error: err.message, - }); + // Fallback to env variable if config.json not found + const envApiUrl = import.meta.env.VITE_API_URL; + if (envApiUrl) { + set({ + apiUrl: envApiUrl, + loaded: true, + error: null, + }); + } else { + console.error('Failed to load config:', err); + set({ + apiUrl: '', + loaded: true, + error: err.message, + }); + } } }, diff --git a/static/config.json b/static/config.json.example similarity index 100% rename from static/config.json rename to static/config.json.example