This commit is contained in:
a 2024-06-13 14:17:04 -05:00
parent 50fb6784f2
commit 97e815547a
No known key found for this signature in database
GPG key ID: 374BC539FE795AF0
2 changed files with 52 additions and 2 deletions

View file

@ -1,4 +1,4 @@
localhost http://localhost:2080
root * src root * src

View file

@ -11,7 +11,7 @@ This directive is a special case: it is evaluated before the structure is parsed
## Syntax ## Syntax
```caddy-d ```caddy-d
import <pattern> [<args...>] import <pattern> [<args...>] [{block}]
``` ```
- **&lt;pattern&gt;** is the filename, glob pattern, or name of [snippet](/docs/caddyfile/concepts#snippets) to include. Its contents will replace this line as if that file's contents appeared here to begin with. - **&lt;pattern&gt;** is the filename, glob pattern, or name of [snippet](/docs/caddyfile/concepts#snippets) to include. Its contents will replace this line as if that file's contents appeared here to begin with.
@ -34,6 +34,11 @@ import <pattern> [<args...>]
Note that prior to v2.7.0, the syntax was `{args.N}` but this form was deprecated in favor of the more flexible syntax above. Note that prior to v2.7.0, the syntax was `{args.N}` but this form was deprecated in favor of the more flexible syntax above.
⚠️ <i>Experimental</i> <span style='white-space: pre;'> | </span> <span>v2.9.x+</span>
- **{block...}** is an optional block to pass to the imported tokens. This placeholder is a special case, and is evaluated recursively at Caddyfile-parse-time, not at runtime. They can be used in two forms:
- `{block}` where the content of provided block will be substituted for the placeholder.
- `{block.key}` where `key` is the first token of a parameter within the provided block
## Examples ## Examples
@ -85,3 +90,48 @@ example.com {
import proxy-rewrite /api 10.0.0.1 10.0.0.2 10.0.0.3 import proxy-rewrite /api 10.0.0.1 10.0.0.2 10.0.0.3
} }
``` ```
⚠️ <i>Experimental</i> <span style='white-space: pre;'> | </span> <span>v2.9.x+</span>
Import a snippet which provides extendable options for a reverse proxy
```caddy
(extendable-proxy) {
reverse_proxy {
to {block.proxy_target}
{block.proxy_options}
}
}
example.com {
import extendable-proxy {
proxy_target 10.0.0.1
proxy_options {
transport http {
tls
}
}
}
}
```
Import a snippet that serves any set of directives, but with a pre-loaded middleware.
```caddy
(instrumented-route) {
header {
Alt-Svc `h3="0.0.0.0:443"; ma=2592000`
}
tracing {
span args[0]
}
{block}
}
example.com {
import instrumented-route example-com {
respond "OK"
}
}
```