Skip to content

Commit

Permalink
fix(middleware): set baseURL to external host if provided
Browse files Browse the repository at this point in the history
  • Loading branch information
twotobinary committed Feb 13, 2020
1 parent aa8bfaf commit 6876565
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
5 changes: 5 additions & 0 deletions pkg/api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,11 @@ func BaseURLMiddleware(next http.Handler) http.Handler {
}
baseURL := scheme + "://" + r.Host

externalHost := config.GetExternalHost()
if externalHost != "" {
baseURL = externalHost
}

r = r.WithContext(context.WithValue(ctx, BaseURLCtxKey, baseURL))

next.ServeHTTP(w, r)
Expand Down
5 changes: 5 additions & 0 deletions pkg/manager/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const MaxStreamingTranscodeSize = "max_streaming_transcode_size"

const Host = "host"
const Port = "port"
const ExternalHost = "external_host"

// Interface options
const SoundOnPreview = "sound_on_preview"
Expand Down Expand Up @@ -108,6 +109,10 @@ func GetPort() int {
return viper.GetInt(Port)
}

func GetExternalHost() string {
return viper.GetString(ExternalHost)
}

func GetMaxTranscodeSize() models.StreamingResolutionEnum {
ret := viper.GetString(MaxTranscodeSize)

Expand Down
15 changes: 8 additions & 7 deletions pkg/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,14 @@ func initFlags() {
}

func initEnvs() {
viper.SetEnvPrefix("stash") // will be uppercased automatically
viper.BindEnv("host") // STASH_HOST
viper.BindEnv("port") // STASH_PORT
viper.BindEnv("stash") // STASH_STASH
viper.BindEnv("generated") // STASH_GENERATED
viper.BindEnv("metadata") // STASH_METADATA
viper.BindEnv("cache") // STASH_CACHE
viper.SetEnvPrefix("stash") // will be uppercased automatically
viper.BindEnv("host") // STASH_HOST
viper.BindEnv("port") // STASH_PORT
viper.BindEnv("external_host") // STASH_EXTERNAL_HOST
viper.BindEnv("stash") // STASH_STASH
viper.BindEnv("generated") // STASH_GENERATED
viper.BindEnv("metadata") // STASH_METADATA
viper.BindEnv("cache") // STASH_CACHE
}

func initFFMPEG() {
Expand Down

0 comments on commit 6876565

Please sign in to comment.