1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-18 20:59:43 +02:00

Improve reverse proxy support

Should address edge cases and close #224 -- subject to field testing.

Does require the NGINX deployments use the following:

proxy_pass <http://documize-url:5001>;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $remote_addr;
This commit is contained in:
sauls8t 2019-04-11 14:45:36 +01:00
parent 9e3eac19aa
commit 1da49974cb
20 changed files with 2108 additions and 731 deletions

View file

@ -22,6 +22,7 @@ import (
"time"
"github.com/documize/community/core/env"
"github.com/documize/community/core/request"
"github.com/documize/community/core/response"
"github.com/documize/community/domain"
"github.com/documize/community/domain/auth"
@ -129,7 +130,7 @@ func (m *middleware) Authorize(w http.ResponseWriter, r *http.Request, next http
rc.ViewUsers = false
rc.AppURL = r.Host
rc.Subdomain = organization.GetSubdomainFromHost(r)
rc.SSL = r.TLS != nil
rc.SSL = request.IsSSL(r)
// get user IP from request
i := strings.LastIndex(r.RemoteAddr, ":")
@ -138,7 +139,6 @@ func (m *middleware) Authorize(w http.ResponseWriter, r *http.Request, next http
} else {
rc.ClientIP = r.RemoteAddr[:i]
}
fip := r.Header.Get("X-Forwarded-For")
if len(fip) > 0 {
rc.ClientIP = fip
@ -262,7 +262,7 @@ func (m *middleware) preAuthorizeStaticAssets(rt *env.Runtime, r *http.Request)
ctx.Analytics = false
ctx.GlobalAdmin = false
ctx.AppURL = r.Host
ctx.SSL = r.TLS != nil
ctx.SSL = request.IsSSL(r)
return true, ctx
}

View file

@ -23,6 +23,7 @@ import (
"github.com/documize/community/domain/store"
"github.com/documize/community/server/routing"
"github.com/documize/community/server/web"
"github.com/gorilla/handlers"
"github.com/gorilla/mux"
)
@ -77,6 +78,9 @@ func Start(rt *env.Runtime, s *store.Store, ready chan struct{}) {
negroni.Wrap(routing.BuildRoutes(rt, routing.RoutePrefixRoot)),
))
// Look out for reverse proxy headers.
router.Use(handlers.ProxyHeaders)
n := negroni.New()
n.Use(negroni.NewStatic(web.StaticAssetsFileSystem()))
n.Use(negroni.HandlerFunc(cm.cors))