src/docs/markdown/caddyfile/directives/invoke.md
<i>⚠️ Experimental</i>
Invokes a named route.
This is useful when paired with HTTP handler directives that have their own in-memory state, or if they are expensive to provision on load. If you have hundreds of sites or more, invoking a named route can help reduce memory usage.
<aside class="tip">Unlike import, invoke does not support arguments, but you may use vars to define variables that can be used within the named route.
invoke [<matcher>] <route-name>
Defines a named route with a reverse_proxy which can be reused in multiple sites, with the same in-memory load balancing state reused for every site.
&(app-proxy) {
reverse_proxy app-01:8080 app-02:8080 app-03:8080 {
lb_policy least_conn
health_uri /healthz
health_interval 5s
}
}
# Apex domain allows accessing the app via an /app subpath
# and the main site otherwise.
example.com {
handle_path /app* {
invoke app-proxy
}
handle {
root /srv
file_server
}
}
# The app is also accessible via a subdomain.
app.example.com {
invoke app-proxy
}