mirror of
https://code.rocketnine.space/tslocum/twins.git
synced 2024-11-27 14:38:14 +01:00
Simplify host configuration
This commit is contained in:
parent
8aec55c459
commit
5637f27b45
3 changed files with 29 additions and 38 deletions
|
@ -24,31 +24,27 @@ certificates:
|
||||||
|
|
||||||
# Hosts and paths to serve
|
# Hosts and paths to serve
|
||||||
hosts:
|
hosts:
|
||||||
-
|
gemini.rocks:
|
||||||
name: gemini.rocks
|
-
|
||||||
paths:
|
path: /sites
|
||||||
-
|
root: /home/gemini.rocks/data/sites
|
||||||
path: /sites
|
-
|
||||||
root: /home/gemini.rocks/data/sites
|
path: ^/(help|info)$
|
||||||
-
|
root: /home/gemini.rocks/data/help
|
||||||
path: ^/(help|info)$
|
-
|
||||||
root: /home/gemini.rocks/data/help
|
path: ^/proxy-example$
|
||||||
-
|
proxy: gemini://localhost:1966
|
||||||
path: ^/proxy-example$
|
-
|
||||||
proxy: gemini://localhost:1966
|
path: ^/cmd-example$
|
||||||
-
|
command: uname -a
|
||||||
path: ^/cmd-example$
|
-
|
||||||
command: uname -a
|
path: /
|
||||||
-
|
root: /home/gemini.rocks/data/home
|
||||||
path: /
|
twins.rocketnine.space:
|
||||||
root: /home/gemini.rocks/data/home
|
-
|
||||||
-
|
path: /sites
|
||||||
name: twins.rocketnine.space
|
root: /home/twins/data/sites
|
||||||
paths:
|
-
|
||||||
-
|
path: /
|
||||||
path: /sites
|
root: /home/twins/data/home
|
||||||
root: /home/twins/data/sites
|
|
||||||
-
|
|
||||||
path: /
|
|
||||||
root: /home/twins/data/home
|
|
||||||
```
|
```
|
11
config.go
11
config.go
|
@ -26,11 +26,6 @@ type pathConfig struct {
|
||||||
cmd []string
|
cmd []string
|
||||||
}
|
}
|
||||||
|
|
||||||
type hostConfig struct {
|
|
||||||
Name string
|
|
||||||
Paths []*pathConfig
|
|
||||||
}
|
|
||||||
|
|
||||||
type certConfig struct {
|
type certConfig struct {
|
||||||
Cert string
|
Cert string
|
||||||
Key string
|
Key string
|
||||||
|
@ -41,7 +36,7 @@ type serverConfig struct {
|
||||||
|
|
||||||
Certificates []*certConfig
|
Certificates []*certConfig
|
||||||
|
|
||||||
Hosts []*hostConfig
|
Hosts map[string][]*pathConfig
|
||||||
|
|
||||||
hostname string
|
hostname string
|
||||||
port int
|
port int
|
||||||
|
@ -83,8 +78,8 @@ func readconfig(configPath string) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, host := range config.Hosts {
|
for _, paths := range config.Hosts {
|
||||||
for _, serve := range host.Paths {
|
for _, serve := range paths {
|
||||||
if serve.Path == "" {
|
if serve.Path == "" {
|
||||||
log.Fatal("path must be specified in serve entry")
|
log.Fatal("path must be specified in serve entry")
|
||||||
} else if (serve.Root != "" && (serve.Proxy != "" || serve.Command != "")) ||
|
} else if (serve.Root != "" && (serve.Proxy != "" || serve.Command != "")) ||
|
||||||
|
|
|
@ -261,13 +261,13 @@ func handleConn(c net.Conn) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var matchedHost bool
|
var matchedHost bool
|
||||||
for _, host := range config.Hosts {
|
for hostname := range config.Hosts {
|
||||||
if requestHostname != host.Name {
|
if requestHostname != hostname {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
matchedHost = true
|
matchedHost = true
|
||||||
|
|
||||||
for _, serve := range host.Paths {
|
for _, serve := range config.Hosts[hostname] {
|
||||||
if serve.Proxy != "" {
|
if serve.Proxy != "" {
|
||||||
if serve.r != nil && serve.r.Match(pathBytes) {
|
if serve.r != nil && serve.r.Match(pathBytes) {
|
||||||
serveProxy(c, requestData, serve.Proxy)
|
serveProxy(c, requestData, serve.Proxy)
|
||||||
|
|
Loading…
Reference in a new issue