Update caddy

main
Kar 2025-05-14 10:41:28 +00:00
parent e292f91d81
commit 76f9e7f9b8
1 changed files with 10 additions and 17 deletions

27
caddy
View File

@ -18,20 +18,17 @@ yourdomain.com {
# Handle OPTIONS preflight requests # Handle OPTIONS preflight requests
@preflight method OPTIONS @preflight method OPTIONS
# Allow both HTTP and HTTPS origins (including localhost) # Workaround for older Caddy versions (no 'origin' matcher)
@allowed_origins { @cors_origin {
origin http://localhost:3000 header Origin ^(http://localhost:3000|https://localhost:3000|https://.*\.example\.com|https://your-production-domain\.com)$
origin https://localhost:3000
origin https://*.example.com
origin https://your-production-domain.com
} }
# CORS headers for actual requests # CORS headers for actual requests
header @allowed_origins Access-Control-Allow-Origin "{http.request.header.origin}" header @cors_origin Access-Control-Allow-Origin "{http.request.header.origin}"
header @allowed_origins Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS" header @cors_origin Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS"
header @allowed_origins Access-Control-Allow-Headers "*" header @cors_origin Access-Control-Allow-Headers "*"
header @allowed_origins Access-Control-Allow-Credentials "true" header @cors_origin Access-Control-Allow-Credentials "true"
header @allowed_origins Vary Origin header @cors_origin Vary Origin
# Special handling for preflight requests # Special handling for preflight requests
header @preflight Access-Control-Allow-Origin "{http.request.header.origin}" header @preflight Access-Control-Allow-Origin "{http.request.header.origin}"
@ -40,13 +37,9 @@ yourdomain.com {
header @preflight Access-Control-Max-Age "3600" header @preflight Access-Control-Max-Age "3600"
# Proxy to your backend # Proxy to your backend
reverse_proxy localhost:8055 { reverse_proxy localhost:8055
header_up Host {host}
header_up X-Real-IP {remote}
header_up X-Forwarded-Proto {scheme}
}
# Ensure OPTIONS requests get 204 responses # Respond to OPTIONS requests immediately
respond @preflight 204 respond @preflight 204
} }