Allow specifying default host and path configuration
This commit is contained in:
parent
4f4e2a8cbe
commit
335a90c5c5
2 changed files with 51 additions and 0 deletions
|
@ -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
|
||||
|
|
43
config.go
43
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)")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue