@sosodev Aha, I made some progress on this.
First I fixed a bug related to matcher tokens. That’s pushed in caddyfile: Fix bug with Delete · caddyserver/caddy@263ffbf · GitHub. Discovered while investigating your question but not relevant in the final solution below.
Then I found a much easier way to do what you want without needing any changes.
If your goal is to simply trigger the reverse proxy if the request does not match a static file on disk:
matcher notStatic {
not {
file {
try_files {path}
}
}
}
reverse_proxy match:notStatic localhost:3000
file_server
Tada!
With this configuration, the try_files
option for the file
matcher will match the request if any of the given files exist. So it simply tries the request path within the root you specified, and if it doesn’t exist, it will not match – but since we’re in a “not” matcher, it negates that and will match!
So you can use that with the reverse proxy, without needing to specify each static file.
Case closed?