mirror of
https://github.com/jech/galene.git
synced 2024-11-09 18:25:58 +01:00
Add new configuration directive proxyURL.
The strategy of computing the base URL from the request doesn't necessarily work if we're behind a reverse proxy. proxyURL can be set in cases where our guess is incorrect. Thanks to Dianne Skoll.
This commit is contained in:
parent
31ed146a95
commit
16e2888d56
3 changed files with 35 additions and 6 deletions
8
README
8
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
|
||||
|
|
|
@ -857,6 +857,7 @@ type Configuration struct {
|
|||
fileSize int64 `json:"-"`
|
||||
|
||||
CanonicalHost string `json:"canonicalHost"`
|
||||
ProxyURL string `json:"proxyURL"`
|
||||
Admin []ClientPattern `json:"admin"`
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue