diff --git a/README b/README index 78620a4..ffb18cd 100644 --- a/README +++ b/README @@ -47,15 +47,19 @@ The server may be configured in the JSON file `data/config.json`. This file may look as follows: { - "canonicalHost": "galene.example.org", "admin":[{"username":"root","password":"secret"}] + "canonicalHost": "galene.example.org", } The fields are as follows: -- `canonicalHost`: the canonical name of the host running the server; +- `proxyURL`: if running behind a reverse proxy, this specifies the + address of the proxy. - `admin` defines the users allowed to look at the `/stats.html` file; it has the same syntax as user definitions in groups (see below). +- `canonicalHost`: the canonical name of the host running the server; this + will cause clients to be redirected if they use a different hostname to + access the server. # Group definitions diff --git a/group/group.go b/group/group.go index 04b9564..73a46bd 100644 --- a/group/group.go +++ b/group/group.go @@ -857,6 +857,7 @@ type Configuration struct { fileSize int64 `json:"-"` CanonicalHost string `json:"canonicalHost"` + ProxyURL string `json:"proxyURL"` Admin []ClientPattern `json:"admin"` } diff --git a/webserver/webserver.go b/webserver/webserver.go index d06a0bb..51b995b 100644 --- a/webserver/webserver.go +++ b/webserver/webserver.go @@ -332,7 +332,18 @@ func groupHandler(w http.ResponseWriter, r *http.Request) { serveFile(w, r, filepath.Join(StaticRoot, "galene.html")) } -func groupBase(r *http.Request) string { +func groupBase(r *http.Request) (string, error) { + conf, err := group.GetConfiguration() + if err != nil { + return "", nil + } + if conf.ProxyURL != "" { + u, err := url.Parse(conf.ProxyURL) + if err != nil { + return "", err + } + return u.JoinPath("/group/").String(), nil + } scheme := "https" if r.TLS == nil { scheme = "http" @@ -342,7 +353,7 @@ func groupBase(r *http.Request) string { Host: r.Host, Path: "/group/", } - return base.String() + return base.String(), nil } func groupStatusHandler(w http.ResponseWriter, r *http.Request) { @@ -364,7 +375,13 @@ func groupStatusHandler(w http.ResponseWriter, r *http.Request) { return } - d := g.Status(false, groupBase(r)) + base, err := groupBase(r) + if err != nil { + http.Error(w, "Internal server error", + http.StatusInternalServerError) + return + } + d := g.Status(false, base) w.Header().Set("content-type", "application/json") w.Header().Set("cache-control", "no-cache") @@ -377,6 +394,13 @@ func groupStatusHandler(w http.ResponseWriter, r *http.Request) { } func publicHandler(w http.ResponseWriter, r *http.Request) { + base, err := groupBase(r) + if err != nil { + log.Println("couldn't determine group base: %v", err) + http.Error(w, "Internal server error", + http.StatusInternalServerError) + return + } w.Header().Set("content-type", "application/json") w.Header().Set("cache-control", "no-cache") @@ -384,7 +408,7 @@ func publicHandler(w http.ResponseWriter, r *http.Request) { return } - g := group.GetPublic(groupBase(r)) + g := group.GetPublic(base) e := json.NewEncoder(w) e.Encode(g) }