fix(middleware): set baseURL to external host if provided (#369)

This commit is contained in:
twotobinary
2020-02-16 19:01:02 -08:00
committed by GitHub
parent df3d3d24f5
commit 776727140f
3 changed files with 18 additions and 7 deletions

View File

@@ -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)

View File

@@ -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"
@@ -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)

View File

@@ -113,6 +113,7 @@ func initEnvs() {
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