From aede987922e4bc48893ef9ff31ceaf25b7237d47 Mon Sep 17 00:00:00 2001 From: CerealBoy Date: Sat, 6 Jul 2024 13:44:52 +1000 Subject: [PATCH] Adding a HOST_VIA_API env to override the API injection for the frontend --- .gitignore | 1 + pkg/config/config.go | 11 +++++++++++ pkg/server/assets.go | 3 +-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 850a7d8..d5641d6 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ *.so *.dylib /episodical +/dist # Test binary, built with `go test -c` *.test diff --git a/pkg/config/config.go b/pkg/config/config.go index f18f6d5..7b9c715 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -1,6 +1,7 @@ package config import ( + "fmt" "log" "os" "strconv" @@ -14,6 +15,7 @@ type Config struct { DataFile string DataPassphrase string Hostname string + HostViaAPI string Port int } @@ -22,6 +24,7 @@ func New() *Config { DataFile: findDataFile(), DataPassphrase: findDataPassphrase(), Hostname: findHostname(), + HostViaAPI: findHostViaAPI(), Port: findPort(), } } @@ -50,6 +53,14 @@ func findHostname() string { return host } +func findHostViaAPI() string { + host := os.Getenv("HOST_VIA_API") + if host == "" { + return fmt.Sprintf("//%s:%d/", findHostname(), findPort()) + } + return host +} + func findPort() int { port, _ := strconv.Atoi(os.Getenv("PORT")) if port < 10 { diff --git a/pkg/server/assets.go b/pkg/server/assets.go index 6ef79d6..e8722f1 100644 --- a/pkg/server/assets.go +++ b/pkg/server/assets.go @@ -3,7 +3,6 @@ package server import ( "bytes" "embed" - "fmt" "net/http" "path" "strings" @@ -35,7 +34,7 @@ func index(c *gin.Context) { s := strings.Replace( string(f), "[EP_BASE_URL]", - fmt.Sprintf("//%s:%d/", conf.Hostname, conf.Port), + conf.HostViaAPI, 1, )