-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathinject-config.sh
More file actions
executable file
·43 lines (34 loc) · 1.42 KB
/
Copy pathinject-config.sh
File metadata and controls
executable file
·43 lines (34 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/sh
# Runtime configuration injection script for frontend
# This script injects runtime configuration into the built React app
echo "🔧 Injecting runtime configuration..."
# Create runtime config object
cat > /usr/share/nginx/html/runtime-config.js << EOF
window.__RUNTIME_CONFIG__ = {
VITE_API_URL: '${VITE_API_URL:-/api}',
VITE_WS_URL: '${VITE_WS_URL:-auto}'
};
console.log('Runtime configuration loaded:', window.__RUNTIME_CONFIG__);
EOF
# Inject the runtime config script into index.html
if [ -f "/usr/share/nginx/html/index.html" ]; then
# Check if runtime config is already injected
if ! grep -q "runtime-config.js" /usr/share/nginx/html/index.html; then
echo "📝 Injecting runtime config script into index.html..."
# Create a temporary file with the script injection
sed 's|<head>|<head>\n <script src="/runtime-config.js"></script>|' /usr/share/nginx/html/index.html > /tmp/index.html.tmp
# Replace the original file
mv /tmp/index.html.tmp /usr/share/nginx/html/index.html
echo "✅ Runtime configuration injected successfully"
else
echo "ℹ️ Runtime config script already present in index.html"
fi
else
echo "❌ Error: index.html not found!"
exit 1
fi
# Log the configuration for debugging
echo "🔍 Current runtime configuration:"
echo " VITE_API_URL: ${VITE_API_URL:-/api}"
echo " VITE_WS_URL: ${VITE_WS_URL:-auto}"
echo "✅ Configuration injection completed"