@marcel91200 / caddy Mirror · read-only / commits / 185ed6fe
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 12, 14:30 UTC

cmd: Assume Caddyfile based on filename prefix and suffix (#5919)

This can be helpful if editors only consider file extensions for certain features. * added special case support for caddyfile suffix, case insensitive * Update cmd/main.go Co-authored-by: Matt Holt <mholt@users.noreply.github.com> * skip caddyfile adapter for registered file extensions --------- Co-authored-by: Matt Holt <mholt@users.noreply.github.com>

Omar Hussein committed Apr 11, 2024 at 17:28 UTC 185ed6fe7c14a88512d7cdcc308477a4f58cca4b
1 file changed +10 -5
cmd/main.go
+10 -5
@@ -157,11 +157,16 @@ func loadConfigWithLogger(logger *zap.Logger, configFile, adapterName string) ([
157 }
158 }
159
160 - // as a special case, if a config file called "Caddyfile" was
161 - // specified, and no adapter is specified, assume caddyfile adapter
162 - // for convenience
163 - if strings.HasPrefix(filepath.Base(configFile), "Caddyfile") &&
164 - filepath.Ext(configFile) != ".json" &&
160 + // as a special case, if a config file starts with "caddyfile" or
161 + // has a ".caddyfile" extension, and no adapter is specified, and
162 + // no adapter module name matches the extension, assume
163 + // caddyfile adapter for convenience
164 + baseConfig := strings.ToLower(filepath.Base(configFile))
165 + baseConfigExt := filepath.Ext(baseConfig)
166 + if (strings.HasPrefix(baseConfig, "caddyfile") ||
167 + strings.HasSuffix(baseConfig, ".caddyfile")) &&
168 + caddyconfig.GetAdapter(baseConfigExt[1:]) == nil &&
169 + baseConfigExt != ".json" &&
170 adapterName == "" {
171 adapterName = "caddyfile"
172 }