Simplify host configuration

This commit is contained in:
Trevor Slocum 2020-10-30 13:36:55 -07:00
parent 8aec55c459
commit 5637f27b45
3 changed files with 29 additions and 38 deletions

View file

@ -24,9 +24,7 @@ certificates:
# Hosts and paths to serve
hosts:
-
name: gemini.rocks
paths:
gemini.rocks:
-
path: /sites
root: /home/gemini.rocks/data/sites
@ -42,9 +40,7 @@ hosts:
-
path: /
root: /home/gemini.rocks/data/home
-
name: twins.rocketnine.space
paths:
twins.rocketnine.space:
-
path: /sites
root: /home/twins/data/sites

View file

@ -26,11 +26,6 @@ type pathConfig struct {
cmd []string
}
type hostConfig struct {
Name string
Paths []*pathConfig
}
type certConfig struct {
Cert string
Key string
@ -41,7 +36,7 @@ type serverConfig struct {
Certificates []*certConfig
Hosts []*hostConfig
Hosts map[string][]*pathConfig
hostname string
port int
@ -83,8 +78,8 @@ func readconfig(configPath string) error {
}
}
for _, host := range config.Hosts {
for _, serve := range host.Paths {
for _, paths := range config.Hosts {
for _, serve := range paths {
if serve.Path == "" {
log.Fatal("path must be specified in serve entry")
} else if (serve.Root != "" && (serve.Proxy != "" || serve.Command != "")) ||

View file

@ -261,13 +261,13 @@ func handleConn(c net.Conn) {
}
var matchedHost bool
for _, host := range config.Hosts {
if requestHostname != host.Name {
for hostname := range config.Hosts {
if requestHostname != hostname {
continue
}
matchedHost = true
for _, serve := range host.Paths {
for _, serve := range config.Hosts[hostname] {
if serve.Proxy != "" {
if serve.r != nil && serve.r.Match(pathBytes) {
serveProxy(c, requestData, serve.Proxy)