diff --git a/Caddyfile b/Caddyfile index 75cdd43..ad82faf 100644 --- a/Caddyfile +++ b/Caddyfile @@ -5,7 +5,35 @@ email ${MAPS_EMAIL} } + +(cors) { + @cors_preflight{args.0} method OPTIONS + @cors{args.0} header Origin {args.0} + + handle @cors_preflight{args.0} { + header { + Access-Control-Allow-Origin "{args.0}" + Access-Control-Allow-Methods "GET, POST, PUT, PATCH, DELETE, OPTIONS" + Access-Control-Allow-Headers * + Access-Control-Max-Age "3600" + defer + } + respond "" 204 + } + + handle @cors{args.0} { + header { + Access-Control-Allow-Origin "{args.0}" + Access-Control-Expose-Headers * + defer + } + } +} + ${MAPS_DOMAIN} { + import cors https://${MAPS_SERVE_DOMAIN} + import cors https://www.${MAPS_SERVE_DOMAIN} + import cors https://*.${MAPS_SERVE_DOMAIN} handle_path /tiles/* { pmtiles_proxy { bucket ${MAPS_PMTILES_LOCATION} diff --git a/entrypoint.sh b/entrypoint.sh index 495a5fe..0f73894 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -6,12 +6,14 @@ echo "Environment variables:" echo "MAPS_DOMAIN=${MAPS_DOMAIN}" echo "MAPS_PMTILES_LOCATION=${MAPS_PMTILES_LOCATION}" echo "MAPS_EMAIL=${MAPS_EMAIL}" +echo "MAPS_SERVE_DOMAIN=${MAPS_SERVE_DOMAIN}" # Replace environment variables in Caddyfile export MAPS_DOMAIN export MAPS_PMTILES_LOCATION export MAPS_EMAIL -envsubst '${MAPS_DOMAIN} ${MAPS_PMTILES_LOCATION} ${MAPS_EMAIL}' < /etc/caddy/Caddyfile.template > /etc/caddy/Caddyfile +export MAPS_SERVE_DOMAIN +envsubst '${MAPS_DOMAIN} ${MAPS_PMTILES_LOCATION} ${MAPS_EMAIL} ${MAPS_SERVE_DOMAIN}' < /etc/caddy/Caddyfile.template > /etc/caddy/Caddyfile echo "Caddyfile:" cat /etc/caddy/Caddyfile