From 477732e245a9601a7f116acc79314caa217ae2b1 Mon Sep 17 00:00:00 2001 From: Leyuan Pan Date: Fri, 7 Oct 2022 10:33:01 -0700 Subject: [PATCH 1/3] Add ExtOrigin for the case behind reverse proxy --- config.go | 11 +++++++++++ server.go | 12 ++---------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/config.go b/config.go index c2c50ab..88e235c 100644 --- a/config.go +++ b/config.go @@ -13,6 +13,7 @@ import ( type Configuration struct { Listen string `config:"tcp://:8080"` Host string `config:"localhost:8080"` + ExtOrigin string `config:""` // consider lfs-test-server may behind a reverse proxy MetaDB string `config:"lfs.db"` ContentPath string `config:"lfs-content"` AdminUser string `config:""` @@ -74,4 +75,14 @@ func init() { // If $PORT is set, override LFS_LISTEN. This is useful for deploying to Heroku. Config.Listen = "tcp://:" + port } + + if Config.ExtOrigin == "" { + // why not ignore the IsHTTPS check and use the following statement directly: + // `Config.ExtOrigin = fmt.Sprintf("%s://%s", Config.Scheme, Config.Host)` + if Config.IsHTTPS() { + Config.ExtOrigin = fmt.Sprintf("%s://%s", Config.Scheme, Config.Host) + } else { + Config.ExtOrigin = fmt.Sprintf("http://%s", Config.Host) + } + } } diff --git a/server.go b/server.go index 0da201b..d9255bf 100644 --- a/server.go +++ b/server.go @@ -131,11 +131,7 @@ func (v *RequestVars) internalLink(subpath string) string { path += fmt.Sprintf("/%s/%s", subpath, v.Oid) - if Config.IsHTTPS() { - return fmt.Sprintf("%s://%s%s", Config.Scheme, Config.Host, path) - } - - return fmt.Sprintf("http://%s%s", Config.Host, path) + return fmt.Sprintf("%s%s", Config.ExtOrigin, path) } func (v *RequestVars) tusLink() string { @@ -149,11 +145,7 @@ func (v *RequestVars) tusLink() string { func (v *RequestVars) VerifyLink() string { path := fmt.Sprintf("/verify/%s", v.Oid) - if Config.IsHTTPS() { - return fmt.Sprintf("%s://%s%s", Config.Scheme, Config.Host, path) - } - - return fmt.Sprintf("http://%s%s", Config.Host, path) + return fmt.Sprintf("%s%s", Config.ExtOrigin, path) } // link provides a structure used to build a hypermedia representation of an HTTP link. From c308ac024177e06596e4e72d5592d5d72f965637 Mon Sep 17 00:00:00 2001 From: Leyuan Pan Date: Fri, 7 Oct 2022 12:35:44 -0700 Subject: [PATCH 2/3] Fix mgmt page regardingExtOrigin --- mgmt/templates/config.tmpl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mgmt/templates/config.tmpl b/mgmt/templates/config.tmpl index 3c83082..0c9085f 100644 --- a/mgmt/templates/config.tmpl +++ b/mgmt/templates/config.tmpl @@ -1,14 +1,14 @@
-

URL: {{.Config.Scheme}}://{{.Config.Host}}

+

URL: {{.Config.ExtOrigin}}

Listen Address: {{.Config.Listen}}

Database: {{.Config.MetaDB}}

Content: {{.Config.ContentPath}}

-

To configure a repository to use this LFS server, add the following to the repository's .gitconfig file:

+

To configure a repository to use this LFS server, add the following to the repository's .lfsconfig file:

 [lfs]
-    url = "{{.Config.Scheme}}://{{.Config.Host}}/"
+    url = "{{.Config.ExtOrigin}}"
 
 
From 55da151b2ebf47e46b39b0edb862739c8b54b158 Mon Sep 17 00:00:00 2001 From: Leyuan Pan Date: Tue, 11 Oct 2022 18:21:43 -0700 Subject: [PATCH 3/3] Minor comments improvements --- config.go | 8 +------- mgmt/templates/config.tmpl | 2 +- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/config.go b/config.go index 88e235c..075294a 100644 --- a/config.go +++ b/config.go @@ -77,12 +77,6 @@ func init() { } if Config.ExtOrigin == "" { - // why not ignore the IsHTTPS check and use the following statement directly: - // `Config.ExtOrigin = fmt.Sprintf("%s://%s", Config.Scheme, Config.Host)` - if Config.IsHTTPS() { - Config.ExtOrigin = fmt.Sprintf("%s://%s", Config.Scheme, Config.Host) - } else { - Config.ExtOrigin = fmt.Sprintf("http://%s", Config.Host) - } + Config.ExtOrigin = fmt.Sprintf("%s://%s", Config.Scheme, Config.Host) } } diff --git a/mgmt/templates/config.tmpl b/mgmt/templates/config.tmpl index 0c9085f..da50a75 100644 --- a/mgmt/templates/config.tmpl +++ b/mgmt/templates/config.tmpl @@ -5,7 +5,7 @@

Content: {{.Config.ContentPath}}

-

To configure a repository to use this LFS server, add the following to the repository's .lfsconfig file:

+

To configure a repository to use this LFS server, add the following to the repository's Git config or .lfsconfig file:

 [lfs]
     url = "{{.Config.ExtOrigin}}"