summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrancis Lavoie <lavofr@gmail.com>2021-02-15 22:10:27 -0500
committerGitHub <noreply@github.com>2021-02-15 20:10:27 -0700
commitbafb562991598df703a744e13cbc06472e71349e (patch)
treea7a68675635b9da5958b9152f20b036b2faa26ad
parented678235a494c07bfb8219bf78c7ba2890377bad (diff)
httpcaddyfile: Configure other apps from global options (#3990)
-rw-r--r--caddyconfig/httpcaddyfile/httptype.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/caddyconfig/httpcaddyfile/httptype.go b/caddyconfig/httpcaddyfile/httptype.go
index a32acab..3f638c9 100644
--- a/caddyconfig/httpcaddyfile/httptype.go
+++ b/caddyconfig/httpcaddyfile/httptype.go
@@ -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 {
}
@@ -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)
}