Simplify CORS handling in Caddyfile by allowing all origins and updating preflight response logic.

This commit is contained in:
Jeppe Bundgaard
2026-02-16 12:31:06 +01:00
parent 739beced0d
commit 0ec8339d3e
+5 -17
View File
@@ -1,16 +1,3 @@
{
# Traefik terminates TLS; Caddy serves HTTP behind Traefik only
auto_https off
}
:80 {
encode gzip
root * /var/www/html
# CORS (reflect allowed origins; credentials-compatible)
# Allow truckwash.dk and truckwash.io subdomains and localhost for dev
@cors_origin header_regexp Origin ^https?://([a-z0-9-]+\.)?truckwash\.(dk|io)(:\d+)?$|^https?://localhost(:\d+)?$
@options method OPTIONS
header @cors_origin {
# Ensure no duplicate CORS headers from upstream app
@@ -19,16 +6,17 @@
-Access-Control-Allow-Methods
-Access-Control-Allow-Headers
-Access-Control-Max-Age
Access-Control-Allow-Origin "{http.request.header.Origin}"
Access-Control-Allow-Origin "*"
Access-Control-Allow-Credentials "true"
Access-Control-Allow-Methods "GET, POST, OPTIONS, PUT, DELETE"
Access-Control-Allow-Headers "Authorization, Content-Type, X-Requested-With, X-Customer-Number"
Access-Control-Allow-Credentials true
Access-Control-Max-Age 86400
Vary Origin
}
# Preflight fast-path
respond @options 204
respond @options 204 {
header @cors_origin
}
# PHP handling via FastCGI to php-fpm pool
php_fastcgi php1:9000 php2:9000 php3:9000 php4:9000 php5:9000