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
This commit is contained in:
mahdahar 2026-02-19 16:34:29 +07:00
parent 1af4adddf7
commit 2e2e65a9f4
5 changed files with 44 additions and 8 deletions

2
.env.example Normal file
View File

@ -0,0 +1,2 @@
# Copy this file to .env.local for local development
VITE_API_URL=http://localhost/clqms01

2
.gitignore vendored
View File

@ -23,4 +23,4 @@ vite.config.js.timestamp-*
vite.config.ts.timestamp-* vite.config.ts.timestamp-*
/.claude /.claude
/.serena /.serenastatic/config.json

24
build.sh Normal file
View File

@ -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

View File

@ -15,7 +15,7 @@ function createConfigStore() {
subscribe, subscribe,
/** /**
* Load configuration from config.json * Load configuration from config.json or env variables
*/ */
load: async () => { load: async () => {
if (!browser) return; if (!browser) return;
@ -32,6 +32,15 @@ function createConfigStore() {
error: null, error: null,
}); });
} catch (err) { } catch (err) {
// 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); console.error('Failed to load config:', err);
set({ set({
apiUrl: '', apiUrl: '',
@ -39,6 +48,7 @@ function createConfigStore() {
error: err.message, error: err.message,
}); });
} }
}
}, },
/** /**