-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.go
More file actions
54 lines (44 loc) · 1.77 KB
/
Copy pathproxy.go
File metadata and controls
54 lines (44 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package matcha
import "fmt"
// proxyDeployArgs builds the docker exec args for kamal-proxy deploy.
func (m *Matcha) proxyDeployArgs(domain string, targetContainer string) []string {
serviceName := m.config.Name
proxyContainer := m.ProxyContainerName()
target := fmt.Sprintf("%s:%d", targetContainer, m.config.AppPort)
args := []string{
"exec", proxyContainer, "kamal-proxy", "deploy", serviceName,
"--target", target,
}
if domain == "localhost" {
// Bare localhost: skip --host (catches all requests) and --tls
} else if isLocalhost(domain) {
// Localhost subdomains (e.g., app.localhost): set --host for routing, skip --tls
args = append(args, "--host", domain)
} else {
args = append(args, "--host", domain, "--tls")
}
args = append(args, "--health-check-path", m.config.HealthPath)
if m.config.HealthTimeout > 0 && m.config.HealthTimeout != 30 {
args = append(args, "--deploy-timeout", fmt.Sprintf("%ds", m.config.HealthTimeout))
}
// Always forward X-Forwarded-* headers so the app gets the real client IP.
// When --tls is set, kamal-proxy defaults to stripping these headers.
// Behind Cloudflare (or any reverse proxy), these headers carry the real IP.
args = append(args, "--forward-headers")
return args
}
// deployToProxy registers the app container with kamal-proxy.
func (m *Matcha) deployToProxy(domain string, targetContainer string) error {
args := m.proxyDeployArgs(domain, targetContainer)
_, err := m.runDocker(args...)
if err != nil {
return fmt.Errorf("kamal-proxy deploy failed: %w", err)
}
return nil
}
// RemoveFromProxy removes the service from kamal-proxy.
func (m *Matcha) RemoveFromProxy() error {
proxyContainer := m.ProxyContainerName()
_, err := m.runDocker("exec", proxyContainer, "kamal-proxy", "remove", m.config.Name)
return err
}