Skip to content

Commit

Permalink
Adding a HOST_VIA_API env to override the API injection for the frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
CerealBoy committed Jul 6, 2024
1 parent 93d7914 commit aede987
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*.so
*.dylib
/episodical
/dist

# Test binary, built with `go test -c`
*.test
Expand Down
11 changes: 11 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package config

import (
"fmt"
"log"
"os"
"strconv"
Expand All @@ -14,6 +15,7 @@ type Config struct {
DataFile string
DataPassphrase string
Hostname string
HostViaAPI string
Port int
}

Expand All @@ -22,6 +24,7 @@ func New() *Config {
DataFile: findDataFile(),
DataPassphrase: findDataPassphrase(),
Hostname: findHostname(),
HostViaAPI: findHostViaAPI(),
Port: findPort(),
}
}
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions pkg/server/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package server
import (
"bytes"
"embed"
"fmt"
"net/http"
"path"
"strings"
Expand Down Expand Up @@ -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,
)

Expand Down

0 comments on commit aede987

Please sign in to comment.