Skip to content

Commit

Permalink
feature(caddy): add cors
Browse files Browse the repository at this point in the history
  • Loading branch information
DragonStuff committed Nov 11, 2024
1 parent ceabfcf commit 509f03f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
28 changes: 28 additions & 0 deletions Caddyfile
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
4 changes: 3 additions & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 509f03f

Please sign in to comment.