diff --git a/CONFIGURATION.md b/CONFIGURATION.md index 6d76186..c446299 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -30,6 +30,10 @@ Fixed string paths will match with and without a trailing slash. When accessing a directory the file `index.gemini` or `index.gmi` is served. +When a host is defined with the name `default`, other hosts and paths will use +those values as the default configuration. It is not currently possible to +enable an attribute by default and then disable it for individual paths. + ### Certificates A certificate and private key must be specified. @@ -162,6 +166,10 @@ listen: :1965 # Hosts and paths to serve hosts: + default: # Default host configuration + paths: # Default path attributes + - + symlinks: true # Follow symbolic links gemini.rocks: cert: /srv/gemini.rocks/data/cert.crt key: /srv/gemini.rocks/data/cert.key diff --git a/config.go b/config.go index 2f07a13..03ebd9a 100644 --- a/config.go +++ b/config.go @@ -123,8 +123,51 @@ func readconfig(configPath string) error { } } + defaultHost := config.Hosts["default"] + delete(config.Hosts, "default") + config.fcgiPools = make(map[string]gofast.ConnFactory) for hostname, host := range config.Hosts { + if defaultHost != nil { + if host.Cert == "" { + host.Cert = defaultHost.Cert + } + if host.Key == "" { + host.Key = defaultHost.Key + } + if len(defaultHost.Paths) == 1 { + defaultPath := defaultHost.Paths[0] + for _, serve := range host.Paths { + if defaultPath.Root != "" && serve.Root == "" { + serve.Root = defaultPath.Root + } + if defaultPath.Proxy != "" && serve.Proxy == "" { + serve.Proxy = defaultPath.Proxy + } + if defaultPath.Command != "" && serve.Command == "" { + serve.Command = defaultPath.Command + } + if defaultPath.SymLinks { + serve.SymLinks = defaultPath.SymLinks + } + if defaultPath.HiddenFiles { + serve.HiddenFiles = defaultPath.HiddenFiles + } + if defaultPath.ListDirectory { + serve.ListDirectory = defaultPath.ListDirectory + } + if defaultPath.Cache != "" && serve.Cache == "" { + serve.Cache = defaultPath.Cache + } + if defaultPath.FastCGI != "" && serve.FastCGI == "" { + serve.FastCGI = defaultPath.FastCGI + } + } + } else if len(defaultHost.Paths) > 1 { + log.Fatal("only one path may be defined for the default host") + } + } + if host.Cert == "" || host.Key == "" { log.Fatal("a certificate must be specified for each domain (gemini requires TLS for all connections)") }