Skip to content

Commit 6400747

Browse files
committed
Improve matcher syntax docs, augment handle_path docs
1 parent dfd5278 commit 6400747

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

src/docs/markdown/caddyfile/directives/handle_path.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,25 @@
22
title: handle_path (Caddyfile directive)
33
---
44

5+
<script>
6+
window.$(function() {
7+
// Add a link to [<path_matcher>] as a special case for this directive.
8+
// The matcher text includes <> characters which are parsed as HTML,
9+
// so we must use text() to change the link text.
10+
window.$('pre.chroma .s:contains("<path_matcher>")')
11+
.map(function(k, item) {
12+
let text = item.innerText.replace(/</g, '&lt;').replace(/>/g, '&gt;');
13+
window.$(item)
14+
.html('<a href="/docs/caddyfile/matchers#path-matchers" style="color: inherit;" title="Matcher token">' + text + '</a>')
15+
.removeClass('s')
16+
.addClass('nd');
17+
});
18+
});
19+
</script>
20+
521
# handle_path
622

7-
Same as the [`handle` directive](/docs/caddyfile/directives/handle), but implicitly strips the matched path prefix.
23+
Works the same as the [`handle` directive](/docs/caddyfile/directives/handle), but implicitly uses [`uri strip_prefix`](/docs/caddyfile/directives/uri) to strip the matched path prefix.
824

925
Handling a request matching a certain path (while stripping that path from the request URI) is a common enough use case that it has its own directive for convenience.
1026

@@ -17,9 +33,9 @@ handle_path <path_matcher> {
1733
}
1834
```
1935

20-
- **<directives...>** is a list of HTTP handler directives or directive blocks, one per line, just like would be used outside of a handle_path block.
36+
- **<directives...>** is a list of HTTP handler directives or directive blocks, one per line, just like would be used outside of a `handle_path` block.
2137

22-
Note that only a single path matcher is accepted and required; you cannot use other kinds of matchers with handle_path.
38+
Only a single [path matcher](/docs/caddyfile/matchers#path-matchers) is accepted, and is required; you cannot use named matchers with `handle_path`.
2339

2440
## Examples
2541

src/docs/markdown/caddyfile/matchers.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ window.$(function() {
5858

5959
In the Caddyfile, a **matcher token** immediately following the directive can limit that directive's scope. The matcher token can be one of these forms:
6060

61-
1. **`*`** to match all requests (wildcard; default).
62-
2. **`/path`** start with a forward slash to match a request path.
63-
3. **`@name`** to specify a _named matcher_.
61+
1. [**`*`**](#wildcard-matchers) to match all requests (wildcard; default).
62+
2. [**`/path`**](#path-matchers) start with a forward slash to match a request path.
63+
3. [**`@name`**](#named-matchers) to specify a _named matcher_.
6464

65-
Matcher tokens are [usually optional](/docs/caddyfile/directives#matchers). If a matcher token is omitted, it is the same as a wildcard matcher (`*`).
65+
If a directive supports matchers, it will appear as `[<matcher>]` in its syntax documentation. Matcher tokens are [usually optional](/docs/caddyfile/directives#syntax), denoted by `[ ]`. If the matcher token is omitted, it is the same as a wildcard matcher (`*`).
6666

6767

6868
#### Examples
@@ -173,6 +173,8 @@ A named matcher definition constitutes a _matcher set_. Matchers in a set are AN
173173

174174
Multiple matchers of the same type may be unioned (e.g. multiple `path` matchers in the same set) using boolean algebra (AND/OR), as described in their respective sections below.
175175

176+
For more complex boolean matching logic, it's recommended to the [`expression` matcher](#expression) to write a CEL expression, which supports _and_ `&&`, _or_ `||`, and _parentheses_ `( )`.
177+
176178

177179

178180

0 commit comments

Comments
 (0)