From c2e7bdaba83aed2ae43b3b2522ff4fc455f62a0b Mon Sep 17 00:00:00 2001 From: Anirudh Oppiliappan Date: Tue, 4 Mar 2025 17:20:24 +0200 Subject: [PATCH] appview/config: add TANGLED_DEV config --- appview/config.go | 1 + appview/state/git_http.go | 8 +++++--- appview/state/signer.go | 7 ++++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/appview/config.go b/appview/config.go index d823f080..8a98695a 100644 --- a/appview/config.go +++ b/appview/config.go @@ -10,6 +10,7 @@ type Config struct { CookieSecret string `env:"TANGLED_COOKIE_SECRET, default=00000000000000000000000000000000"` DbPath string `env:"TANGLED_DB_PATH, default=appview.db"` ListenAddr string `env:"TANGLED_LISTEN_ADDR, default=0.0.0.0:3000"` + Dev bool `env:"TANGLED_DEV, default=false"` } func LoadConfig(ctx context.Context) (*Config, error) { diff --git a/appview/state/git_http.go b/appview/state/git_http.go index 224c0351..2399f961 100644 --- a/appview/state/git_http.go +++ b/appview/state/git_http.go @@ -14,8 +14,11 @@ func (s *State) InfoRefs(w http.ResponseWriter, r *http.Request) { knot := r.Context().Value("knot").(string) repo := chi.URLParam(r, "repo") - // TODO: make this https for production! - targetURL := fmt.Sprintf("https://%s/%s/%s/info/refs?%s", knot, user.DID, repo, r.URL.RawQuery) + uri := "https" + if s.config.Dev { + uri = "http" + } + targetURL := fmt.Sprintf("%s://%s/%s/%s/info/refs?%s", uri, knot, user.DID, repo, r.URL.RawQuery) resp, err := http.Get(targetURL) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) @@ -47,7 +50,6 @@ func (s *State) UploadPack(w http.ResponseWriter, r *http.Request) { } knot := r.Context().Value("knot").(string) repo := chi.URLParam(r, "repo") - // TODO: make this https for production! targetURL := fmt.Sprintf("https://%s/%s/%s/git-upload-pack?%s", knot, user.DID, repo, r.URL.RawQuery) client := &http.Client{} diff --git a/appview/state/signer.go b/appview/state/signer.go index 92ff28b8..9877c8d5 100644 --- a/appview/state/signer.go +++ b/appview/state/signer.go @@ -9,6 +9,7 @@ import ( "fmt" "net/http" "net/url" + "os" "time" ) @@ -41,7 +42,11 @@ func NewSignedClient(domain, secret string) (*SignedClient, error) { }, } - url, err := url.Parse(fmt.Sprintf("https://%s", domain)) + uri := "https" + if os.Getenv("TANGLED_DEV") == "true" { + uri = "http" + } + url, err := url.Parse(fmt.Sprintf("%s://%s", uri, domain)) if err != nil { return nil, err } -- knotmirror 0.0.1