Skip to content

Commit

Permalink
Merge pull request #110 from bluvec/main
Browse files Browse the repository at this point in the history
#75 add ExtOrigin config to handle lfs-test-server behind a reverse proxy case
  • Loading branch information
chrisd8088 authored Oct 12, 2022
2 parents 0ef8949 + 3418fd4 commit 24ca93f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
5 changes: 5 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:""`
Expand Down Expand Up @@ -74,4 +75,8 @@ func init() {
// If $PORT is set, override LFS_LISTEN. This is useful for deploying to Heroku.
Config.Listen = "tcp://:" + port
}

if Config.ExtOrigin == "" {
Config.ExtOrigin = fmt.Sprintf("%s://%s", Config.Scheme, Config.Host)
}
}
6 changes: 3 additions & 3 deletions mgmt/templates/config.tmpl
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<div class="container">
<p><strong>URL:</strong> {{.Config.Scheme}}://{{.Config.Host}}</p>
<p><strong>URL:</strong> {{.Config.ExtOrigin}}</p>
<p><strong>Listen Address:</strong> {{.Config.Listen}}</p>
<p><strong>Database:</strong> {{.Config.MetaDB}}</p>
<p><strong>Content:</strong> {{.Config.ContentPath}}</p>
</div>
<div class="container">
<p>To configure a repository to use this LFS server, add the following to the repository's <code>.gitconfig</code> file:</p>
<p>To configure a repository to use this LFS server, add the following to the repository's Git config or <code>.lfsconfig</code> file:</p>
<pre>
<code>[lfs]
url = "{{.Config.Scheme}}://{{.Config.Host}}/"
url = "{{.Config.ExtOrigin}}"
</code>
</pre>

Expand Down
12 changes: 2 additions & 10 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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.
Expand Down

0 comments on commit 24ca93f

Please sign in to comment.