diff --git a/start.sh b/start.sh index 98759ed..b1d09ab 100644 --- a/start.sh +++ b/start.sh @@ -1194,14 +1194,12 @@ done # Set up Caddy web server echo "==> Setting up Caddy web server" -# First inject the config.js script tags into all HTML files -echo "==> Injecting config.js into web application HTML files" - -# Create writable data directories for web assets -mkdir -p /app/data/web/photos /app/data/web/accounts /app/data/web/auth /app/data/web/cast +# Create a simpler approach for injecting configuration +echo "==> Creating a static HTML file with config scripts already included" # Create runtime-config.js files in writable locations echo "==> Creating runtime-config.js in writable location" +mkdir -p /app/data/web cat > /app/data/web/runtime-config.js < Copying and modifying index.html for $app_dir app" + cp "/app/web/$app_dir/index.html" "/app/data/web/$app_dir/index.html" + + # Fix any potential issues with the head tag + if ! grep -q "" "/app/data/web/$app_dir/index.html"; then + echo "==> Warning: No head tag found in $app_dir/index.html, adding one" + sed -i 's//\n<\/head>/' "/app/data/web/$app_dir/index.html" + fi + + # Insert config scripts right after the opening head tag, unescaped + sed -i 's//\n + + + Ente $app_dir + + +

Ente $app_dir

+

Loading...

+

If this page doesn't redirect automatically, click here.

+ + +HTML + fi done -# Ensure all files are readable -chmod -R 644 /app/data/web/runtime-config.js - -# Update the Caddy configuration to serve config.js directly +# Modify the Caddyfile to serve our modified HTML files cat > /app/data/caddy/Caddyfile < /app/data/caddy/Caddyfile < /app/data/caddy/Caddyfile < - - - - - - {http.vars.head_content} - - - {http.vars.body_content} - -" - } - } - - # Main photos app - rewrite to use the index-with-config + + # Root path serves the photos app handle / { - root * /app/web/photos - - # Rewrite index.html to include our config - @isroot { - path / + # Special handling for index.html + @is_index path / + handle @is_index { + root * /app/data/web/photos + try_files {path} /index.html + file_server } - # For other files just serve them directly - file_server - - # Special handling for index.html to inject scripts - handle @isroot { - rewrite * /index-with-config.html - vars { - head_content "" - body_content "" - } - reverse_proxy http://localhost:$CADDY_PORT { - header_up Host {host} - } + # Serve other static files from the original location + @not_index { + not path / + not path /api/* + not path /public/* + not path /accounts/* + not path /auth/* + not path /cast/* + } + handle @not_index { + root * /app/web/photos + try_files {path} /index.html + file_server } } - + # Next.js static files handle /_next/* { root * /app/web/photos @@ -1336,71 +1348,83 @@ cat > /app/data/caddy/Caddyfile < /app/data/caddy/Caddyfile < Created Caddy config with static HTML files at /app/data/caddy/Caddyfile" +echo "==> Created Caddy config with properly modified HTML files at /app/data/caddy/Caddyfile" # Start Caddy server echo "==> Starting Caddy server"