Simplify Caddyfile configuration to fix syntax error
This commit is contained in:
parent
ece40fe707
commit
6c1903b5a4
68
start.sh
68
start.sh
@ -172,10 +172,18 @@ if ! command -v caddy &> /dev/null; then
|
|||||||
apt-get update && apt-get install -y caddy
|
apt-get update && apt-get install -y caddy
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Set up Caddy to serve the web apps and proxy to the Museum server
|
# Set up the API endpoint for the web apps
|
||||||
echo "==> Setting up Caddy for web apps and API"
|
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
|
mkdir -p /app/data/caddy
|
||||||
cat > /app/data/caddy/Caddyfile <<EOT
|
cat > /app/data/caddy/Caddyfile <<EOT
|
||||||
{
|
{
|
||||||
@ -211,35 +219,11 @@ cat > /app/data/caddy/Caddyfile <<EOT
|
|||||||
Access-Control-Allow-Credentials "true"
|
Access-Control-Allow-Credentials "true"
|
||||||
}
|
}
|
||||||
|
|
||||||
# For debugging - public access to the config.js
|
# Simple JavaScript file that defines the API endpoint
|
||||||
handle /debug/config.js {
|
handle /api-config.js {
|
||||||
root * /app/data/caddy/public
|
respond "window.ENTE_CONFIG = { API_URL: '${API_ENDPOINT}' };" 200 {
|
||||||
file_server
|
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
|
# Photos app - root path
|
||||||
@ -812,28 +796,6 @@ echo "==> Ente is now running!"
|
|||||||
echo "==> Museum server: PID $SERVER_PID"
|
echo "==> Museum server: PID $SERVER_PID"
|
||||||
echo "==> Caddy: PID $CADDY_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 for child processes to exit
|
||||||
wait $SERVER_PID
|
wait $SERVER_PID
|
||||||
wait $CADDY_PID
|
wait $CADDY_PID
|
Loading…
x
Reference in New Issue
Block a user