Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#75 add ExtOrigin config to handle lfs-test-server behind a reverse proxy case #110

Merged
merged 6 commits into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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