Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 14, 05:15 UTC
httpcaddyfile: Configure other apps from global options (#3990)
Francis Lavoie committed
Feb 15, 2021 at 22:10 UTC
bafb562991598df703a744e13cbc06472e71349e
1 file changed
+22
caddyconfig/httpcaddyfile/httptype.go
+22
@@ -36,6 +36,17 @@ func init() {
36
caddyconfig.RegisterAdapter("caddyfile", caddyfile.Adapter{ServerType: ServerType{}})
37
}
38
39
+// App represents the configuration for a non-standard
40
+// Caddy app module (e.g. third-party plugin) which was
41
+// parsed from a global options block.
42
+type App struct {
43
+ // The JSON key for the app being configured
44
+ Name string
45
+
46
+ // The raw app config as JSON
47
+ Value json.RawMessage
48
+}
49
+
50
// ServerType can set up a config from an HTTP Caddyfile.
51
type ServerType struct {
52
}
@@ -260,6 +271,17 @@ func (st ServerType) Setup(inputServerBlocks []caddyfile.ServerBlock,
271
272
// annnd the top-level config, then we're done!
273
cfg := &caddy.Config{AppsRaw: make(caddy.ModuleMap)}
274
+
275
+ // loop through the configured options, and if any of
276
+ // them are an httpcaddyfile App, then we insert them
277
+ // into the config as raw Caddy apps
278
+ for _, opt := range options {
279
+ if app, ok := opt.(App); ok {
280
+ cfg.AppsRaw[app.Name] = app.Value
281
+ }
282
+ }
283
+
284
+ // insert the standard Caddy apps into the config
285
if len(httpApp.Servers) > 0 {
286
cfg.AppsRaw["http"] = caddyconfig.JSON(httpApp, &warnings)
287
}