Browse Source

added domain scheme/host for proxied docker containers

pull/141/head
Thomas Schädler 6 years ago
parent
commit
ef11dc5091
3 changed files with 35 additions and 0 deletions
  1. +16
    -0
      cmd/cmd.go
  2. +9
    -0
      server/handlers.go
  3. +10
    -0
      server/server.go

+ 16
- 0
cmd/cmd.go View File

@@ -173,6 +173,16 @@ var globalFlags = []cli.Flag{
Usage: "pass for http basic auth",
Value: "",
},
cli.StringFlag{
Name: "domain-url-scheme",
Usage: "domain url scheme (http or https) when running behind a proxy",
Value: "",
},
cli.StringFlag{
Name: "domain-url-host",
Usage: "domain url host (fqdn) when running behind a proxy",
Value: "",
},
}

type Cmd struct {
@@ -308,6 +318,12 @@ func New() *Cmd {
panic("Provider not set or invalid.")
}

if domainUrlScheme := c.String("domain-url-scheme"); domainUrlScheme == "" {
} else if domainUrlHost := c.String("domain-url-host"); domainUrlHost == "" {
} else {
options = append(options, server.DomainUrl(domainUrlScheme, domainUrlHost))
}

srvr, err := server.New(
options...,
)


+ 9
- 0
server/handlers.go View File

@@ -300,6 +300,11 @@ func (s *Server) postHandler(w http.ResponseWriter, r *http.Request) {
}

relativeURL, _ := url.Parse(path.Join(token, filename))
var mappedUrl = getURL(r)
if s.DomainUrlScheme != "" && s.DomainUrlHost != "" {
mappedUrl.Scheme = s.DomainUrlScheme
mappedUrl.Host = s.DomainUrlHost
}
fmt.Fprint(w, getURL(r).ResolveReference(relativeURL).String())
}
}
@@ -443,6 +448,10 @@ func (s *Server) putHandler(w http.ResponseWriter, r *http.Request) {

w.Header().Set("X-Url-Delete", resolveUrl(r, deleteUrl, true))

if s.DomainUrlScheme != "" && s.DomainUrlHost != "" {
relativeURL.Scheme = s.DomainUrlScheme
relativeURL.Host = s.DomainUrlHost
}
fmt.Fprint(w, resolveUrl(r, relativeURL, false))
}



+ 10
- 0
server/server.go View File

@@ -210,6 +210,13 @@ func HttpAuthCredentials(user string, pass string) OptionFn {
}
}

func DomainUrl(scheme string, host string) OptionFn {
return func(srvr *Server) {
srvr.DomainUrlScheme = scheme
srvr.DomainUrlHost = host
}
}

type Server struct {
AuthUser string
AuthPass string
@@ -244,6 +251,9 @@ type Server struct {
Certificate string

LetsEncryptCache string
DomainUrlScheme string
DomainUrlHost string
}

func New(options ...OptionFn) (*Server, error) {


Loading…
Cancel
Save