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