diff --git a/start.sh b/start.sh index 5b88ff0..ec0b397 100644 --- a/start.sh +++ b/start.sh @@ -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" +# Set up the API endpoint for the web apps +API_ENDPOINT=${CLOUDRON_APP_ORIGIN}/api +echo "==> Setting API endpoint to $API_ENDPOINT" -# Create a custom Caddy configuration in the writable data directory +# 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 < /app/data/caddy/Caddyfile <; rel=preload; as=script" + # 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" } - 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 - } - } - - # 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 @@ -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|||' "$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