Skip to content

Commit 9a2f194

Browse files
authored
Merge pull request #88 from dsanader/master
Adds a listening address setting
2 parents 4debdba + 3691f64 commit 9a2f194

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

lib/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
)
88

99
type Config struct {
10+
Laddr string `json:"laddr"`
1011
Port int `json:"port"`
1112
ProxyTo string `json:"proxy_to"`
1213
}

lib/proxy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func (p *Proxy) Run(config *Config) error {
3535
p.proxy = httputil.NewSingleHostReverseProxy(url)
3636
p.to = url
3737

38-
p.listener, err = net.Listen("tcp", fmt.Sprintf(":%d", config.Port))
38+
p.listener, err = net.Listen("tcp", fmt.Sprintf("%s:%d", config.Laddr, config.Port))
3939
if err != nil {
4040
return err
4141
}

main.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ func main() {
3333
app.Usage = "A live reload utility for Go web applications."
3434
app.Action = MainAction
3535
app.Flags = []cli.Flag{
36+
cli.StringFlag{
37+
Name: "laddr,l",
38+
Value: "",
39+
Usage: "listening address for the proxy server",
40+
},
3641
cli.IntFlag{
3742
Name: "port,p",
3843
Value: 3000,
@@ -86,6 +91,7 @@ func main() {
8691
}
8792

8893
func MainAction(c *cli.Context) {
94+
laddr := c.GlobalString("laddr")
8995
port := c.GlobalInt("port")
9096
appPort := strconv.Itoa(c.GlobalInt("appPort"))
9197
immediate = c.GlobalBool("immediate")
@@ -107,6 +113,7 @@ func MainAction(c *cli.Context) {
107113
proxy := gin.NewProxy(builder, runner)
108114

109115
config := &gin.Config{
116+
Laddr: laddr,
110117
Port: port,
111118
ProxyTo: "http://localhost:" + appPort,
112119
}
@@ -116,7 +123,11 @@ func MainAction(c *cli.Context) {
116123
logger.Fatal(err)
117124
}
118125

119-
logger.Printf("listening on port %d\n", port)
126+
if laddr != "" {
127+
logger.Printf("listening at %s:%d\n", laddr, port)
128+
} else {
129+
logger.Printf("listening on port %d\n", port)
130+
}
120131

121132
shutdown(runner)
122133

0 commit comments

Comments
 (0)