Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cmd/cli/cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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())
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 3 additions & 5 deletions cmd/cli/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ package cmd

import (
"fmt"
"log/slog"
"os"

"github.com/joho/godotenv"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -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 == "" {
Expand Down
12 changes: 9 additions & 3 deletions internal/api/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,17 @@ func DeployHandler(deployer Deployer, fs FunctionStore) http.HandlerFunc {
slog.Error("failed to deactivate old versions", "error", err)
}

host, _, err := net.SplitHostPort(r.Host)
if err != nil {
host = 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 = clientHost
}
// 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)
Expand Down
6 changes: 6 additions & 0 deletions internal/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions internal/service/deploy_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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 {
Expand Down
Loading