Skip to content

Commit

Permalink
fix: allow subdomain regex
Browse files Browse the repository at this point in the history
  • Loading branch information
DragonStuff committed Nov 11, 2024
1 parent 509f03f commit d8c150f
Showing 1 changed file with 21 additions and 24 deletions.
45 changes: 21 additions & 24 deletions Caddyfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,37 @@
email ${MAPS_EMAIL}
}


(cors) {
@cors_preflight{args.0} method OPTIONS
@cors{args.0} header Origin {args.0}
@origin header Origin {args.0}
header @origin {
Access-Control-Allow-Origin "{header.Origin}"
Access-Control-Allow-Methods "GET, POST, PUT, PATCH, DELETE, OPTIONS"
Access-Control-Allow-Headers "*"
Access-Control-Allow-Credentials "true"
Access-Control-Max-Age "3600"
defer
}
}

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
${MAPS_DOMAIN} {
# Match any subdomain pattern for CORS
@allowed_origins {
expression {header.Origin}.matches('^https://([a-zA-Z0-9-]+\\.)*${MAPS_SERVE_DOMAIN}$')
}

handle @cors{args.0} {
header {
Access-Control-Allow-Origin "{args.0}"
Access-Control-Expose-Headers *
defer
}
header @allowed_origins {
Access-Control-Allow-Origin "{header.Origin}"
Access-Control-Allow-Methods "*"
Access-Control-Allow-Headers "*"
Access-Control-Allow-Credentials "true"
Access-Control-Max-Age "3600"
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}
cache_size 19000
# used to embed a tiles URL in TileJSON.
public_url https://${MAPS_DOMAIN}/tiles
}
}
Expand Down

0 comments on commit d8c150f

Please sign in to comment.