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:
parent
1af4adddf7
commit
2e2e65a9f4
2
.env.example
Normal file
2
.env.example
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
# Copy this file to .env.local for local development
|
||||||
|
VITE_API_URL=http://localhost/clqms01
|
||||||
2
.gitignore
vendored
2
.gitignore
vendored
@ -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
24
build.sh
Normal 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
|
||||||
@ -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,12 +32,22 @@ function createConfigStore() {
|
|||||||
error: null,
|
error: null,
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Failed to load config:', err);
|
// Fallback to env variable if config.json not found
|
||||||
set({
|
const envApiUrl = import.meta.env.VITE_API_URL;
|
||||||
apiUrl: '',
|
if (envApiUrl) {
|
||||||
loaded: true,
|
set({
|
||||||
error: err.message,
|
apiUrl: envApiUrl,
|
||||||
});
|
loaded: true,
|
||||||
|
error: null,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
console.error('Failed to load config:', err);
|
||||||
|
set({
|
||||||
|
apiUrl: '',
|
||||||
|
loaded: true,
|
||||||
|
error: err.message,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user