That works by chance.
Here is the order of the directives: Caddyfile Directives — Caddy Documentation
And here’s a page that describes your scenario exactly (but with a different directive) and explains why it is this way and how to use the route
directive: route (Caddyfile directive) — Caddy Documentation
You could also use handle
instead.
And here’s a wiki post that goes into more detail about writing Caddyfiles: Composing in the Caddyfile