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:
|
||||
-
|
||||
name: gemini.rocks
|
||||
paths:
|
||||
-
|
||||
path: /sites
|
||||
root: /home/gemini.rocks/data/sites
|
||||
-
|
||||
path: ^/(help|info)$
|
||||
root: /home/gemini.rocks/data/help
|
||||
-
|
||||
path: ^/proxy-example$
|
||||
proxy: gemini://localhost:1966
|
||||
-
|
||||
path: ^/cmd-example$
|
||||
command: uname -a
|
||||
-
|
||||
path: /
|
||||
root: /home/gemini.rocks/data/home
|
||||
-
|
||||
name: twins.rocketnine.space
|
||||
paths:
|
||||
-
|
||||
path: /sites
|
||||
root: /home/twins/data/sites
|
||||
-
|
||||
path: /
|
||||
root: /home/twins/data/home
|
||||
gemini.rocks:
|
||||
-
|
||||
path: /sites
|
||||
root: /home/gemini.rocks/data/sites
|
||||
-
|
||||
path: ^/(help|info)$
|
||||
root: /home/gemini.rocks/data/help
|
||||
-
|
||||
path: ^/proxy-example$
|
||||
proxy: gemini://localhost:1966
|
||||
-
|
||||
path: ^/cmd-example$
|
||||
command: uname -a
|
||||
-
|
||||
path: /
|
||||
root: /home/gemini.rocks/data/home
|
||||
twins.rocketnine.space:
|
||||
-
|
||||
path: /sites
|
||||
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
|
||||
}
|
||||
|
||||
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 != "")) ||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue