Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
v2 proposal: New 'route' directive for Caddyfile #2911
The v2 Caddyfile makes most simple sites easy to set up because the order of the directives does not matter, unlike with Caddy's native JSON. For example, in the Caddyfile, you can put a
Similarly, you'd want compression to come after templates, so that templates doesn't operate on a compressed, binary stream.
The point is, the order matters, and the Caddyfile takes away the fuss of ordering by hard-coding the order for you. With the Caddyfile, it is much harder to write routes with logical errors due to handler order.
However, this is not ideal for all situations. Sometimes, you want a redirect before a rewrite for example, or you want one directive to immediately precede another so that they act as one unit.
The Caddyfile makes it difficult to gain extra control; currently, one has to drop down to JSON and craft their route manually.
However, it seems that a widespread need could be satisfied with a way to execute directives in the order they appear in some isolation (i.e. not a global change).
All matching route blocks would be executed first, in the order of appearance in the Caddyfile, before other directives.
Matchers cannot be defined in routes.
Directives outside of routes keep to the hard-coded/pre-defined order. This helps reduce user error and is still easy enough for simple configs. This way, the order won't matter for most users. Routes are intended to be an advanced feature to give you more control without having to drop all the way down to JSON.
Matching routes are always executed first, i.e. they take priority over directives outside a route block.
One major nuance is that