Skip to content

Commit 0ce138e

Browse files
committed
fix: show target host in list output
1 parent a179fe6 commit 0ce138e

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

daemon.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,8 @@ func (d *Daemon) hello(w http.ResponseWriter, r *http.Request) {
254254
func (d *Daemon) listClients(w http.ResponseWriter, r *http.Request) {
255255
w.WriteHeader(200)
256256
fmt.Fprintln(w, "vhosts:")
257-
for host, v := range d.vhost.Servers {
258-
fmt.Fprintf(w, "%s -> %s:%d\n", host, v.Host, v.Port)
257+
for _, v := range d.vhost.Servers {
258+
fmt.Fprintf(w, "%s -> %s:%d\n", v.Host, v.ServiceHost, v.Port)
259259
}
260260
}
261261

vhost.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,16 @@ import (
1111
"github.com/cbednarski/hostess/hostess"
1212
)
1313

14+
// Vhost represents a single backend service
1415
type Vhost struct {
15-
Host string
16-
Port int
16+
Host string // virtual host name
17+
18+
ServiceHost string // service host or IP
19+
Port int // service port
20+
1721
Handler http.Handler
18-
Cert string
19-
Key string
22+
Cert string // TLS Certificate
23+
Key string // TLS Private Key
2024
}
2125

2226
// VhostMux is an http.Handler whose ServeHTTP forwards the request to
@@ -79,14 +83,15 @@ func CreateVhost(input string, useTLS bool) (*Vhost, error) {
7983
if err != nil {
8084
return nil, fmt.Errorf("failed to parse target port: %s", err)
8185
}
86+
targetHost := "127.0.0.1"
8287

83-
proxy := CreateProxy(url.URL{Scheme: "http", Host: fmt.Sprintf("127.0.0.1:%d", targetPort)}, hostname)
88+
proxy := CreateProxy(url.URL{Scheme: "http", Host: fmt.Sprintf("%s:%d", targetHost, targetPort)}, hostname)
8489

8590
// Add IP to hosts
8691
addToHosts(hostname)
8792

8893
vhost := &Vhost{
89-
Host: hostname, Port: targetPort, Handler: proxy,
94+
Host: hostname, ServiceHost: targetHost, Port: targetPort, Handler: proxy,
9095
}
9196

9297
if useTLS {

0 commit comments

Comments
 (0)