Caddy and CORS

Sat, Mar 30, 2024 One-minute read

Caddy and CORS

A quick Caddy CORS snippet


(cors) {
	@cors_preflight method OPTIONS
	@cors header Origin {args.0}

	handle @cors_preflight {
		header Access-Control-Allow-Origin "{args.0}"
		header Access-Control-Allow-Methods "GET, POST, PUT, PATCH, DELETE"
		header Access-Control-Allow-Headers "Content-Type, Authorization"
		header Access-Control-Max-Age "3600"
		respond "" 204
	}

	handle @cors {
		header Access-Control-Allow-Origin "{args.0}"
		header Access-Control-Expose-Headers "Link"
	}
}

server1 {
	encode gzip
	tls internal
	import cors https://server2
	reverse_proxy https://192.168.20.10:5000 {
		transport http {
			tls_insecure_skip_verify
		}
	}
}

Tags:

#caddy #cors #til