mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-30 22:34:15 -05:00
caddyfile: Use of vars no longer requires nesting in subroutes
This is because of our sequential handling logic which was recently merged; if vars is the first handler in the chain, it will be run before the next route's matchers are executed, so there's no need to nest the handlers anymore.
This commit is contained in:
parent
994b9033e9
commit
29315847a8
1 changed files with 5 additions and 29 deletions
|
@ -318,10 +318,7 @@ func (st *ServerType) serversFromPairings(
|
||||||
return nil, fmt.Errorf("server block %v: compiling matcher sets: %v", sblock.block.Keys, err)
|
return nil, fmt.Errorf("server block %v: compiling matcher sets: %v", sblock.block.Keys, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// if there are user-defined variables, then siteVarSubroute will
|
siteSubroute := new(caddyhttp.Subroute)
|
||||||
// wrap the handlerSubroute; otherwise handlerSubroute will be the
|
|
||||||
// site's primary subroute.
|
|
||||||
siteVarSubroute, handlerSubroute := new(caddyhttp.Subroute), new(caddyhttp.Subroute)
|
|
||||||
|
|
||||||
// tls: connection policies and toggle auto HTTPS
|
// tls: connection policies and toggle auto HTTPS
|
||||||
|
|
||||||
|
@ -357,10 +354,10 @@ func (st *ServerType) serversFromPairings(
|
||||||
// TODO: consolidate equal conn policies
|
// TODO: consolidate equal conn policies
|
||||||
}
|
}
|
||||||
|
|
||||||
// vars: special routes that will have to wrap the normal handlers
|
// vars: make sure these are linked in first so future
|
||||||
// so that these variables can be used across their matchers too
|
// routes can use the variables they define
|
||||||
for _, cfgVal := range sblock.pile["var"] {
|
for _, cfgVal := range sblock.pile["var"] {
|
||||||
siteVarSubroute.Routes = append(siteVarSubroute.Routes, cfgVal.Value.(caddyhttp.Route))
|
siteSubroute.Routes = append(siteSubroute.Routes, cfgVal.Value.(caddyhttp.Route))
|
||||||
}
|
}
|
||||||
|
|
||||||
// set up each handler directive - the order of the handlers
|
// set up each handler directive - the order of the handlers
|
||||||
|
@ -437,28 +434,7 @@ func (st *ServerType) serversFromPairings(
|
||||||
r.Value = route
|
r.Value = route
|
||||||
}
|
}
|
||||||
|
|
||||||
handlerSubroute.Routes = append(handlerSubroute.Routes, r.Value.(caddyhttp.Route))
|
siteSubroute.Routes = append(siteSubroute.Routes, r.Value.(caddyhttp.Route))
|
||||||
}
|
|
||||||
|
|
||||||
// the route that contains the site's handlers will
|
|
||||||
// be assumed to be the sub-route for this site...
|
|
||||||
siteSubroute := handlerSubroute
|
|
||||||
|
|
||||||
// ... unless, of course, there are variables that might
|
|
||||||
// be used by the site's matchers or handlers, in which
|
|
||||||
// case we need to nest the handlers in a sub-sub-route,
|
|
||||||
// and the variables go in the sub-route so the variables
|
|
||||||
// get evaluated first
|
|
||||||
if len(siteVarSubroute.Routes) > 0 {
|
|
||||||
subSubRoute := caddyhttp.Subroute{Routes: siteSubroute.Routes}
|
|
||||||
siteSubroute.Routes = append(
|
|
||||||
siteVarSubroute.Routes,
|
|
||||||
caddyhttp.Route{
|
|
||||||
HandlersRaw: []json.RawMessage{
|
|
||||||
caddyconfig.JSONModuleObject(subSubRoute, "handler", "subroute", warnings),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
siteSubroute.Routes = consolidateRoutes(siteSubroute.Routes)
|
siteSubroute.Routes = consolidateRoutes(siteSubroute.Routes)
|
||||||
|
|
Loading…
Reference in a new issue