Loading start.sh +16 −54 Original line number Diff line number Diff line Loading @@ -172,10 +172,18 @@ if ! command -v caddy &> /dev/null; then apt-get update && apt-get install -y caddy fi # Set up Caddy to serve the web apps and proxy to the Museum server echo "==> Setting up Caddy for web apps and API" # Create a custom Caddy configuration in the writable data directory # Set up the API endpoint for the web apps API_ENDPOINT=${CLOUDRON_APP_ORIGIN}/api echo "==> Setting API endpoint to $API_ENDPOINT" # Set environment variables for the web apps export ENTE_API_ENDPOINT=$API_ENDPOINT export NEXT_PUBLIC_ENTE_ENDPOINT=$API_ENDPOINT export REACT_APP_ENTE_ENDPOINT=$API_ENDPOINT export VUE_APP_ENTE_ENDPOINT=$API_ENDPOINT echo "==> Set environment variables for web apps" # Create a very simple Caddy configuration mkdir -p /app/data/caddy cat > /app/data/caddy/Caddyfile <<EOT { Loading Loading @@ -211,35 +219,11 @@ cat > /app/data/caddy/Caddyfile <<EOT Access-Control-Allow-Credentials "true" } # For debugging - public access to the config.js handle /debug/config.js { root * /app/data/caddy/public file_server # Simple JavaScript file that defines the API endpoint handle /api-config.js { respond "window.ENTE_CONFIG = { API_URL: '${API_ENDPOINT}' };" 200 { Content-Type "application/javascript" } # Create a special handler for index.html files to inject our config @indexhtml { path_regexp index .*\/index\.html$ } # Handle the direct window variable configuration better handle @indexhtml { # Inject a non-defer, early-loading script that defines ENTE_CONFIG respond_early_hints { link "</config.js>; rel=preload; as=script" } header Content-Type "text/html; charset=utf-8" replace_response_headers Content-Length "" rewrite_early { # This injects the script into the head section of any index.html r </head> <script>window.ENTE_CONFIG = { API_URL: "${CLOUDRON_APP_ORIGIN}/api" };</script></head> } } # Configuration available via JavaScript handle /config.js { header Content-Type "application/javascript" respond "window.ENTE_CONFIG = { API_URL: '${CLOUDRON_APP_ORIGIN}/api' }; console.log('Ente config loaded with API_URL:', window.ENTE_CONFIG.API_URL);" } # Photos app - root path Loading Loading @@ -812,28 +796,6 @@ echo "==> Ente is now running!" echo "==> Museum server: PID $SERVER_PID" echo "==> Caddy: PID $CADDY_PID" # Function to inject the config.js script tag into index.html files inject_config_script() { echo "==> Attempting to inject config.js script tag into index.html files" # List of web app directories WEB_APPS=("/app/web/photos" "/app/web/accounts" "/app/web/auth" "/app/web/cast") for app_dir in "${WEB_APPS[@]}"; do if [ -f "$app_dir/index.html" ]; then echo "==> Processing $app_dir/index.html" # Try to modify in place without creating a backup sed -i 's|</head>|<script>window.ENTE_CONFIG = { API_URL: "'"${CLOUDRON_APP_ORIGIN}"'/api" };</script></head>|' "$app_dir/index.html" || echo "==> Cannot modify $app_dir/index.html - read-only file system" else echo "==> Skipping $app_dir - index.html not found" fi done } # Try to inject the config script but don't worry if it fails inject_config_script || echo "==> NOTE: Could not inject configuration directly into HTML files" # Wait for child processes to exit wait $SERVER_PID wait $CADDY_PID No newline at end of file Loading
start.sh +16 −54 Original line number Diff line number Diff line Loading @@ -172,10 +172,18 @@ if ! command -v caddy &> /dev/null; then apt-get update && apt-get install -y caddy fi # Set up Caddy to serve the web apps and proxy to the Museum server echo "==> Setting up Caddy for web apps and API" # Create a custom Caddy configuration in the writable data directory # Set up the API endpoint for the web apps API_ENDPOINT=${CLOUDRON_APP_ORIGIN}/api echo "==> Setting API endpoint to $API_ENDPOINT" # Set environment variables for the web apps export ENTE_API_ENDPOINT=$API_ENDPOINT export NEXT_PUBLIC_ENTE_ENDPOINT=$API_ENDPOINT export REACT_APP_ENTE_ENDPOINT=$API_ENDPOINT export VUE_APP_ENTE_ENDPOINT=$API_ENDPOINT echo "==> Set environment variables for web apps" # Create a very simple Caddy configuration mkdir -p /app/data/caddy cat > /app/data/caddy/Caddyfile <<EOT { Loading Loading @@ -211,35 +219,11 @@ cat > /app/data/caddy/Caddyfile <<EOT Access-Control-Allow-Credentials "true" } # For debugging - public access to the config.js handle /debug/config.js { root * /app/data/caddy/public file_server # Simple JavaScript file that defines the API endpoint handle /api-config.js { respond "window.ENTE_CONFIG = { API_URL: '${API_ENDPOINT}' };" 200 { Content-Type "application/javascript" } # Create a special handler for index.html files to inject our config @indexhtml { path_regexp index .*\/index\.html$ } # Handle the direct window variable configuration better handle @indexhtml { # Inject a non-defer, early-loading script that defines ENTE_CONFIG respond_early_hints { link "</config.js>; rel=preload; as=script" } header Content-Type "text/html; charset=utf-8" replace_response_headers Content-Length "" rewrite_early { # This injects the script into the head section of any index.html r </head> <script>window.ENTE_CONFIG = { API_URL: "${CLOUDRON_APP_ORIGIN}/api" };</script></head> } } # Configuration available via JavaScript handle /config.js { header Content-Type "application/javascript" respond "window.ENTE_CONFIG = { API_URL: '${CLOUDRON_APP_ORIGIN}/api' }; console.log('Ente config loaded with API_URL:', window.ENTE_CONFIG.API_URL);" } # Photos app - root path Loading Loading @@ -812,28 +796,6 @@ echo "==> Ente is now running!" echo "==> Museum server: PID $SERVER_PID" echo "==> Caddy: PID $CADDY_PID" # Function to inject the config.js script tag into index.html files inject_config_script() { echo "==> Attempting to inject config.js script tag into index.html files" # List of web app directories WEB_APPS=("/app/web/photos" "/app/web/accounts" "/app/web/auth" "/app/web/cast") for app_dir in "${WEB_APPS[@]}"; do if [ -f "$app_dir/index.html" ]; then echo "==> Processing $app_dir/index.html" # Try to modify in place without creating a backup sed -i 's|</head>|<script>window.ENTE_CONFIG = { API_URL: "'"${CLOUDRON_APP_ORIGIN}"'/api" };</script></head>|' "$app_dir/index.html" || echo "==> Cannot modify $app_dir/index.html - read-only file system" else echo "==> Skipping $app_dir - index.html not found" fi done } # Try to inject the config script but don't worry if it fails inject_config_script || echo "==> NOTE: Could not inject configuration directly into HTML files" # Wait for child processes to exit wait $SERVER_PID wait $CADDY_PID No newline at end of file