Route templates: a route named x-* serves any request route x-<something>

Implemented-By: OpenCode session (model recorded in docs/implementer-log.md)
This commit is contained in:
2026-09-25 13:38:24 -07:00
parent 4863e53eb8
commit 4e1dd03d07
10 changed files with 344 additions and 9 deletions
+5 -5
View File
@@ -144,13 +144,13 @@ func (p *Handler) route(r *http.Request) (route, rest string, code int, msg stri
if hdr != "" {
rest := r.URL.Path
// A path that also carries a (different) route name is a client mistake: the header is the
// operator's intent, but the path disagrees.
// operator's intent, but the path disagrees. Compare concrete names.
if rname, _, ok := SplitRoute(rest); ok {
if _, known := p.cfg.Routes[rname]; known && rname != hdr {
if _, _, rok := p.cfg.Route(rname); rok && rname != hdr {
return "", "", http.StatusBadRequest, "conflicting route"
}
}
if _, known := p.cfg.Routes[hdr]; !known {
if _, _, ok := p.cfg.Route(hdr); !ok {
return "", "", http.StatusNotFound, "unknown route"
}
if !allowedPath(rest) {
@@ -162,7 +162,7 @@ func (p *Handler) route(r *http.Request) (route, rest string, code int, msg stri
if !ok {
return "", "", http.StatusBadRequest, "missing route"
}
if _, known := p.cfg.Routes[route]; !known {
if _, _, ok := p.cfg.Route(route); !ok {
return "", "", http.StatusNotFound, "unknown route"
}
if !allowedPath(rest) {
@@ -207,7 +207,7 @@ func (p *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
p.writeError(w, code, msg)
return
}
routeCfg := p.cfg.Routes[route]
routeCfg, _, _ := p.cfg.Route(route)
model, body, err := peekModel(r)
if err != nil {