Provision sets up the app.
(ctx caddy.Context)
| 176 | |
| 177 | // Provision sets up the app. |
| 178 | func (app *App) Provision(ctx caddy.Context) error { |
| 179 | // store some references |
| 180 | app.logger = ctx.Logger() |
| 181 | app.ctx = ctx |
| 182 | |
| 183 | // provision TLS and events apps |
| 184 | tlsAppIface, err := ctx.App("tls") |
| 185 | if err != nil { |
| 186 | return fmt.Errorf("getting tls app: %v", err) |
| 187 | } |
| 188 | app.tlsApp = tlsAppIface.(*caddytls.TLS) |
| 189 | |
| 190 | eventsAppIface, err := ctx.App("events") |
| 191 | if err != nil { |
| 192 | return fmt.Errorf("getting events app: %v", err) |
| 193 | } |
| 194 | |
| 195 | repl := caddy.NewReplacer() |
| 196 | |
| 197 | // this provisions the matchers for each route, |
| 198 | // and prepares auto HTTP->HTTPS redirects, and |
| 199 | // is required before we provision each server |
| 200 | err = app.automaticHTTPSPhase1(ctx, repl) |
| 201 | if err != nil { |
| 202 | return err |
| 203 | } |
| 204 | |
| 205 | if app.Metrics != nil { |
| 206 | app.Metrics.init = sync.Once{} |
| 207 | app.Metrics.httpMetrics = &httpMetrics{} |
| 208 | // Scan config for allowed hosts to prevent cardinality explosion |
| 209 | app.Metrics.scanConfigForHosts(app) |
| 210 | if err := app.Metrics.provisionOTLP(ctx); err != nil { |
| 211 | return err |
| 212 | } |
| 213 | } |
| 214 | // prepare each server |
| 215 | oldContext := ctx.Context |
| 216 | for srvName, srv := range app.Servers { |
| 217 | ctx.Context = context.WithValue(oldContext, ServerCtxKey, srv) |
| 218 | srv.name = srvName |
| 219 | srv.tlsApp = app.tlsApp |
| 220 | srv.events = eventsAppIface.(*caddyevents.App) |
| 221 | srv.ctx = ctx |
| 222 | srv.logger = app.logger.Named("log") |
| 223 | srv.errorLogger = app.logger.Named("log.error") |
| 224 | if srv.Metrics != nil { |
| 225 | srv.logger.Warn("per-server 'metrics' is deprecated; use 'metrics' in the root 'http' app instead") |
| 226 | app.Metrics = cmp.Or(app.Metrics, &Metrics{ |
| 227 | init: sync.Once{}, |
| 228 | httpMetrics: &httpMetrics{}, |
| 229 | }) |
| 230 | app.Metrics.PerHost = app.Metrics.PerHost || srv.Metrics.PerHost |
| 231 | } |
| 232 | |
| 233 | // only enable access logs if configured |
| 234 | if srv.Logs != nil { |
| 235 | srv.accessLogger = app.logger.Named("log.access") |
nothing calls this directly
no test coverage detected