diff --git a/start.sh b/start.sh index 12dada2..94e8323 100644 --- a/start.sh +++ b/start.sh @@ -206,7 +206,7 @@ if ! command -v caddy &> /dev/null; then fi # Set up the API endpoint for the web apps -API_ENDPOINT=${CLOUDRON_APP_ORIGIN}/api +API_ENDPOINT="${CLOUDRON_APP_ORIGIN}/api" echo "==> Setting API endpoint to $API_ENDPOINT" # Set environment variables for the web apps @@ -216,100 +216,249 @@ 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 +# Create directory for direct modifications +mkdir -p /app/data/scripts + +# Create a script that will directly define the ENTE_CONFIG global in window +cat > /app/data/scripts/ente-config.js < Setting up Caddy server for web apps" +mkdir -p /app/data/caddy/public cat > /app/data/caddy/Caddyfile < Caddy configuration created at /app/data/caddy/Caddyfile" +# Create HTML transformer script to modify all index.html files on load +mkdir -p /app/data/scripts +cat > /app/data/scripts/insert-config.sh <||' "/app/data/temp.html" + + # Create a symlink from the modified file to the original + # Only if the temp file was created and modified successfully + if [ -f "/app/data/temp.html" ]; then + mkdir -p "/app/data/transformed/\$(basename \$app_dir)" + cp "/app/data/temp.html" "/app/data/transformed/\$(basename \$app_dir)/index.html" + fi + fi +done + +echo "All index.html files processed" +EOT +chmod +x /app/data/scripts/insert-config.sh + +# Run the transformer script to create modified index.html files +mkdir -p /app/data/transformed +echo "==> Creating modified index.html files with injected configuration" +/app/data/scripts/insert-config.sh + +# Create direct configuration files for different frameworks +mkdir -p /app/data/public +echo "==> Creating framework-specific configuration files" + +# Create a Next.js public runtime configuration +cat > /app/data/public/env.js < /app/data/public/config.json < "/app/data/public/${app_name}-config.html" < + + + + Loading ${app_name} + + + + +

Loading ${app_name}...

+

If you are not redirected automatically, click here.

+

Debug Information

+ + +EOT +done + +echo "==> Created app-specific config loading pages with debug info" + # Looking for Museum (Go server component) echo "==> Looking for Museum (Go server component)" @@ -812,4 +961,216 @@ echo "==> Caddy: PID $CADDY_PID" # Wait for child processes to exit wait $SERVER_PID -wait $CADDY_PID \ No newline at end of file +wait $CADDY_PID + +# Create a special root index.html that loads the config and redirects +cat > /app/data/public/index.html < + + + + Ente + + + + +

Loading Ente...

+

You will be redirected automatically.

+

Debug Information

+ + +EOT + +echo "==> Created special root index.html with configuration" + +# Create debug script for frontend +mkdir -p /app/data/public +mkdir -p /app/data/debug + +echo "==> Creating debug scripts" +cat > /app/data/public/debug.js <' + + 'process.env.NEXT_PUBLIC_ENTE_ENDPOINT: ' + (window.process?.env?.NEXT_PUBLIC_ENTE_ENDPOINT || 'undefined') + '
' + + 'localStorage ENTE_CONFIG: ' + localStorage.getItem('ENTE_CONFIG') + '
' + + 'localStorage NEXT_PUBLIC_ENTE_ENDPOINT: ' + localStorage.getItem('NEXT_PUBLIC_ENTE_ENDPOINT'); + debugDiv.appendChild(configInfo); + + // Add toggle button + const toggleButton = document.createElement('button'); + toggleButton.innerText = 'Toggle Debug Info'; + toggleButton.style.marginTop = '10px'; + toggleButton.onclick = function() { + configInfo.style.display = configInfo.style.display === 'none' ? 'block' : 'none'; + }; + debugDiv.appendChild(toggleButton); + + // Add to document when it's ready + if (document.body) { + document.body.appendChild(debugDiv); + } else { + window.addEventListener('DOMContentLoaded', function() { + document.body.appendChild(debugDiv); + }); + } +})(); +EOT + +# Create debug info script that prints environment info +cat > /app/data/debug/debug_env.js < /app/data/public/debug.html < + + + + Ente Debug Info + + + +

Ente Debug Information

+ +
+

Frontend Configuration

+
Loading...
+
+ +
+

URL Test

+

Testing URL construction with API endpoint:

+
Running test...
+
+ +
+

API Health Check

+
Checking API health...
+
+ + + + +EOT \ No newline at end of file