Skip to content

Commit

Permalink
httpcaddyfile: Configure other apps from global options (#3990)
Browse files Browse the repository at this point in the history
  • Loading branch information
francislavoie committed Feb 16, 2021
1 parent ed67823 commit bafb562
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions caddyconfig/httpcaddyfile/httptype.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ func init() {
caddyconfig.RegisterAdapter("caddyfile", caddyfile.Adapter{ServerType: ServerType{}})
}

// App represents the configuration for a non-standard
// Caddy app module (e.g. third-party plugin) which was
// parsed from a global options block.
type App struct {
// The JSON key for the app being configured
Name string

// The raw app config as JSON
Value json.RawMessage
}

// ServerType can set up a config from an HTTP Caddyfile.
type ServerType struct {
}
Expand Down Expand Up @@ -260,6 +271,17 @@ func (st ServerType) Setup(inputServerBlocks []caddyfile.ServerBlock,

// annnd the top-level config, then we're done!
cfg := &caddy.Config{AppsRaw: make(caddy.ModuleMap)}

// loop through the configured options, and if any of
// them are an httpcaddyfile App, then we insert them
// into the config as raw Caddy apps
for _, opt := range options {
if app, ok := opt.(App); ok {
cfg.AppsRaw[app.Name] = app.Value
}
}

// insert the standard Caddy apps into the config
if len(httpApp.Servers) > 0 {
cfg.AppsRaw["http"] = caddyconfig.JSON(httpApp, &warnings)
}
Expand Down

0 comments on commit bafb562

Please sign in to comment.