From 36b81240a9c0919219c8d94ce7fe7efee5b0f631 Mon Sep 17 00:00:00 2001 From: sreyasppradeep1455 Date: Mon, 6 Apr 2026 13:18:31 +0530 Subject: [PATCH 1/3] chore: cleanup the codebase --- internal/api/deploy.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/api/deploy.go b/internal/api/deploy.go index c08f96a..6638c02 100644 --- a/internal/api/deploy.go +++ b/internal/api/deploy.go @@ -129,7 +129,7 @@ func DeployHandler(deployer Deployer, fs FunctionStore) http.HandlerFunc { if err != nil { host = r.Host } - + // For local development, allow "localhost" as host. In production, expect real hostname. var endpoint string if host == "localhost" || host == "127.0.0.1" { endpoint = fmt.Sprintf("%s.localhost", functionName) From cef3ff48e72e3654dcb687f54fe513363bcd7362 Mon Sep 17 00:00:00 2001 From: sreyasppradeep1455 Date: Mon, 6 Apr 2026 13:35:39 +0530 Subject: [PATCH 2/3] fix: preserve client host through proxy for correct deploy endpoint generation --- internal/api/deploy.go | 10 ++++++++-- internal/proxy/proxy.go | 6 ++++++ internal/service/deploy_service.go | 4 ++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/internal/api/deploy.go b/internal/api/deploy.go index 6638c02..31db580 100644 --- a/internal/api/deploy.go +++ b/internal/api/deploy.go @@ -125,9 +125,15 @@ func DeployHandler(deployer Deployer, fs FunctionStore) http.HandlerFunc { slog.Error("failed to deactivate old versions", "error", err) } - host, _, err := net.SplitHostPort(r.Host) + // Get the original host from proxy header, or use direct request host + clientHost := r.Header.Get("X-Forwarded-Host") + if clientHost == "" { + clientHost = r.Host + } + + host, _, err := net.SplitHostPort(clientHost) if err != nil { - host = r.Host + host = clientHost } // For local development, allow "localhost" as host. In production, expect real hostname. var endpoint string diff --git a/internal/proxy/proxy.go b/internal/proxy/proxy.go index 6106754..862fe92 100644 --- a/internal/proxy/proxy.go +++ b/internal/proxy/proxy.go @@ -99,6 +99,9 @@ func ProxyHandler(targetURL *url.URL, timeoutSecs ...int) http.Handler { out.Header[k] = vv } + // Preserve original client host for backend to generate correct endpoint URLs + out.Header.Set("X-Forwarded-Host", req.Host) + slog.Info("control plane request", "path", req.URL.Path, "method", req.Method) return } @@ -117,6 +120,9 @@ func ProxyHandler(targetURL *url.URL, timeoutSecs ...int) http.Handler { out.Header[k] = vv } + // Preserve original client host for backend to generate correct endpoint URLs + out.Header.Set("X-Forwarded-Host", req.Host) + slog.Info("invoke request", "function", fn) if req.Method == http.MethodGet { diff --git a/internal/service/deploy_service.go b/internal/service/deploy_service.go index d6de277..8ba0104 100644 --- a/internal/service/deploy_service.go +++ b/internal/service/deploy_service.go @@ -33,7 +33,7 @@ func (d *Deployer) Deploy(ctx context.Context, name string, file io.Reader, out logger := slog.With("function", name) cyan := color.New(color.FgCyan) - _, _ = fmt.Fprint(out, "\n[2/3] Building image ") + _, _ = fmt.Fprint(out, "\n[4/5] Building image ") _, _ = cyan.Fprintf(out, "\"func-%s\"", name) _, _ = fmt.Fprint(out, "...\n\n") @@ -59,7 +59,7 @@ func (d *Deployer) Deploy(ctx context.Context, name string, file io.Reader, out return err } - _, _ = fmt.Fprint(out, "\n[3/3] Pushing image...") + _, _ = fmt.Fprint(out, "\n[5/5] Pushing image...") logger.Info("image_lifecycle", "stage", "pushing") if err := d.imageClient.PushImage(ctx, target); err != nil { From 662733daf017056d18e2e372877bb868a2e98bd0 Mon Sep 17 00:00:00 2001 From: sreyasppradeep1455 Date: Mon, 6 Apr 2026 13:49:44 +0530 Subject: [PATCH 3/3] chore(cli): cleaning up the logs --- cmd/cli/cmd/deploy.go | 6 +++--- cmd/cli/cmd/root.go | 8 +++----- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/cmd/cli/cmd/deploy.go b/cmd/cli/cmd/deploy.go index 2b29378..87db45e 100644 --- a/cmd/cli/cmd/deploy.go +++ b/cmd/cli/cmd/deploy.go @@ -39,7 +39,7 @@ to quickly create a Cobra application.`, } //create a tar stream of the function directory - fmt.Print("[1/3] Packaging function code...") + fmt.Print("[1/5] Packaging function code...") tarstream, err := buildcontext.CreateTarStream(abspath, runtimeName) if err != nil { color.Red(" Failed. \n\n%s\n", err.Error()) @@ -51,7 +51,7 @@ to quickly create a Cobra application.`, } // Check if function already exists and ask for confirmation if not using --force - fmt.Print("[2/3] Checking if function exists...") + fmt.Print("[2/5] Checking if function exists...") functionExists, err := checkFunctionExists(functionName) if err != nil { color.Red(" Failed. \n\n%s\n", err.Error()) @@ -82,7 +82,7 @@ to quickly create a Cobra application.`, url := fmt.Sprintf("%s/functions", serverAddr) // Stream deploy logs from server - fmt.Print("[3/3] Deploying function...") + fmt.Print("[3/5] Deploying function...") err = buildcontext.SendTarStream(tarstream, url, functionName) if err != nil { slog.Error("deployment failed", "error", err) diff --git a/cmd/cli/cmd/root.go b/cmd/cli/cmd/root.go index 8fd19f2..e514429 100644 --- a/cmd/cli/cmd/root.go +++ b/cmd/cli/cmd/root.go @@ -5,10 +5,8 @@ package cmd import ( "fmt" - "log/slog" "os" - "github.com/joho/godotenv" "github.com/spf13/cobra" ) @@ -48,9 +46,9 @@ func init() { // Cobra also supports local flags, which will only run // when this action is called directly. - if err := godotenv.Load(); err != nil { - slog.Warn("could not load .env file, using default configuration") - } + // if err := godotenv.Load(); err != nil { + // slog.Warn("could not load .env file, using default configuration") + // } // Use PROXY_URL for proxy endpoint, fallback to localhost targetUrl := os.Getenv("PROXY_URL") if targetUrl == "" {