Fixed empty HTML issue by copying and modifying the original HTML files

This commit is contained in:
Andreas Düren 2025-03-18 20:16:12 +01:00
parent bdcf96150f
commit 71db4afae1

194
start.sh
View File

@ -1194,14 +1194,12 @@ done
# Set up Caddy web server # Set up Caddy web server
echo "==> Setting up Caddy web server" echo "==> Setting up Caddy web server"
# First inject the config.js script tags into all HTML files # Create a simpler approach for injecting configuration
echo "==> Injecting config.js into web application HTML files" echo "==> Creating a static HTML file with config scripts already included"
# 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 runtime-config.js files in writable locations # Create runtime-config.js files in writable locations
echo "==> Creating runtime-config.js in writable location" echo "==> Creating runtime-config.js in writable location"
mkdir -p /app/data/web
cat > /app/data/web/runtime-config.js <<EOT cat > /app/data/web/runtime-config.js <<EOT
// Runtime configuration for Ente // Runtime configuration for Ente
window.ENTE_CONFIG = { window.ENTE_CONFIG = {
@ -1220,15 +1218,50 @@ console.log('API_URL:', window.ENTE_CONFIG.API_URL);
console.log('PUBLIC_ALBUMS_URL:', window.ENTE_CONFIG.PUBLIC_ALBUMS_URL); console.log('PUBLIC_ALBUMS_URL:', window.ENTE_CONFIG.PUBLIC_ALBUMS_URL);
EOT EOT
# Copy the runtime-config.js to each app directory # Ensure runtime-config.js is readable
for app_dir in /app/data/web/photos /app/data/web/accounts /app/data/web/auth /app/data/web/cast; do chmod 644 /app/data/web/runtime-config.js
cp /app/data/web/runtime-config.js "$app_dir/"
# Create the static HTML files with scripts pre-injected
for app_dir in photos accounts auth cast; do
# Create directory for our modified files
mkdir -p /app/data/web/$app_dir
# If the original index.html exists, copy and modify it
if [ -f "/app/web/$app_dir/index.html" ]; then
echo "==> 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 "<head>" "/app/data/web/$app_dir/index.html"; then
echo "==> Warning: No head tag found in $app_dir/index.html, adding one"
sed -i 's/<html>/<html>\n<head><\/head>/' "/app/data/web/$app_dir/index.html"
fi
# Insert config scripts right after the opening head tag, unescaped
sed -i 's/<head>/<head>\n <script src="\/config.js" type="text\/javascript"><\/script>\n <script src="\/runtime-config.js" type="text\/javascript"><\/script>/' "/app/data/web/$app_dir/index.html"
else
# Create a minimal HTML file with the scripts included but pointing to the original app
echo "==> Creating minimal pre-configured index.html for $app_dir app with redirect"
cat > "/app/data/web/$app_dir/index.html" <<HTML
<!DOCTYPE html>
<html>
<head>
<script src="/config.js" type="text/javascript"></script>
<script src="/runtime-config.js" type="text/javascript"></script>
<meta http-equiv="refresh" content="0;url=/app/web/$app_dir/index.html">
<title>Ente $app_dir</title>
</head>
<body>
<h1>Ente $app_dir</h1>
<p>Loading...</p>
<p>If this page doesn't redirect automatically, <a href="/app/web/$app_dir/index.html">click here</a>.</p>
</body>
</html>
HTML
fi
done done
# Ensure all files are readable # Modify the Caddyfile to serve our modified HTML files
chmod -R 644 /app/data/web/runtime-config.js
# Update the Caddy configuration to serve config.js directly
cat > /app/data/caddy/Caddyfile <<EOT cat > /app/data/caddy/Caddyfile <<EOT
# Global settings # Global settings
{ {
@ -1246,7 +1279,7 @@ cat > /app/data/caddy/Caddyfile <<EOT
output file /app/data/logs/caddy.log output file /app/data/logs/caddy.log
} }
# Configuration scripts - This must come before the root handler # Configuration scripts - directly served
handle /config.js { handle /config.js {
header Content-Type application/javascript header Content-Type application/javascript
respond " respond "
@ -1272,50 +1305,29 @@ cat > /app/data/caddy/Caddyfile <<EOT
file_server file_server
} }
# Create special routes for index.html that add script tags # Root path serves the photos app
handle /index-with-config.html {
@is_index_html {
path /index-with-config.html
}
header @is_index_html Content-Type text/html
respond @is_index_html 200 {
body "<!DOCTYPE html>
<html>
<head>
<script src=\"/config.js\" type=\"text\/javascript\"></script>
<script src=\"/runtime-config.js\" type=\"text\/javascript\"></script>
<!-- Placeholder for original head content -->
{http.vars.head_content}
</head>
<body>
{http.vars.body_content}
</body>
</html>"
}
}
# Main photos app - rewrite to use the index-with-config
handle / { handle / {
root * /app/web/photos # Special handling for index.html
@is_index path /
# Rewrite index.html to include our config handle @is_index {
@isroot { root * /app/data/web/photos
path / try_files {path} /index.html
file_server
} }
# For other files just serve them directly # Serve other static files from the original location
file_server @not_index {
not path /
# Special handling for index.html to inject scripts not path /api/*
handle @isroot { not path /public/*
rewrite * /index-with-config.html not path /accounts/*
vars { not path /auth/*
head_content "<!-- Head content from photos app -->" not path /cast/*
body_content "<!-- Body content from photos app -->" }
} handle @not_index {
reverse_proxy http://localhost:$CADDY_PORT { root * /app/web/photos
header_up Host {host} try_files {path} /index.html
} file_server
} }
} }
@ -1336,71 +1348,83 @@ cat > /app/data/caddy/Caddyfile <<EOT
# Accounts app # Accounts app
handle /accounts { handle /accounts {
header Content-Type text/html root * /app/data/web/accounts
respond 200 {file}/app/data/web/accounts/index.html try_files {path} /index.html
file_server
} }
handle /accounts/* { handle /accounts/* {
@is_index { @is_index path /accounts/ /accounts/index.html
path /accounts/ handle @is_index {
path /accounts/index.html root * /app/data/web
try_files /accounts/index.html
file_server
} }
header @is_index Content-Type text/html
respond @is_index 200 {file}/app/data/web/accounts/index.html
@not_index { @not_index {
not path /accounts/ not path /accounts/
not path /accounts/index.html not path /accounts/index.html
} }
uri strip_prefix /accounts handle @not_index {
root @not_index /app/web/accounts uri strip_prefix /accounts
file_server @not_index root * /app/web/accounts
try_files {path} /index.html
file_server
}
} }
# Auth app # Auth app
handle /auth { handle /auth {
header Content-Type text/html root * /app/data/web/auth
respond 200 {file}/app/data/web/auth/index.html try_files {path} /index.html
file_server
} }
handle /auth/* { handle /auth/* {
@is_index { @is_index path /auth/ /auth/index.html
path /auth/ handle @is_index {
path /auth/index.html root * /app/data/web
try_files /auth/index.html
file_server
} }
header @is_index Content-Type text/html
respond @is_index 200 {file}/app/data/web/auth/index.html
@not_index { @not_index {
not path /auth/ not path /auth/
not path /auth/index.html not path /auth/index.html
} }
uri strip_prefix /auth handle @not_index {
root @not_index /app/web/auth uri strip_prefix /auth
file_server @not_index root * /app/web/auth
try_files {path} /index.html
file_server
}
} }
# Cast app # Cast app
handle /cast { handle /cast {
header Content-Type text/html root * /app/data/web/cast
respond 200 {file}/app/data/web/cast/index.html try_files {path} /index.html
file_server
} }
handle /cast/* { handle /cast/* {
@is_index { @is_index path /cast/ /cast/index.html
path /cast/ handle @is_index {
path /cast/index.html root * /app/data/web
try_files /cast/index.html
file_server
} }
header @is_index Content-Type text/html
respond @is_index 200 {file}/app/data/web/cast/index.html
@not_index { @not_index {
not path /cast/ not path /cast/
not path /cast/index.html not path /cast/index.html
} }
uri strip_prefix /cast handle @not_index {
root @not_index /app/web/cast uri strip_prefix /cast
file_server @not_index root * /app/web/cast
try_files {path} /index.html
file_server
}
} }
# Main API proxy # Main API proxy
@ -1436,7 +1460,7 @@ cat > /app/data/caddy/Caddyfile <<EOT
} }
EOT EOT
echo "==> 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 # Start Caddy server
echo "==> Starting Caddy server" echo "==> Starting Caddy server"