Skip to content
Merged
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
1 change: 1 addition & 0 deletions lib/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
)

type Config struct {
Laddr string `json:"laddr"`
Port int `json:"port"`
ProxyTo string `json:"proxy_to"`
}
Expand Down
2 changes: 1 addition & 1 deletion lib/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (p *Proxy) Run(config *Config) error {
p.proxy = httputil.NewSingleHostReverseProxy(url)
p.to = url

p.listener, err = net.Listen("tcp", fmt.Sprintf(":%d", config.Port))
p.listener, err = net.Listen("tcp", fmt.Sprintf("%s:%d", config.Laddr, config.Port))
if err != nil {
return err
}
Expand Down
13 changes: 12 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ func main() {
app.Usage = "A live reload utility for Go web applications."
app.Action = MainAction
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "laddr,l",
Value: "",
Usage: "listening address for the proxy server",
},
cli.IntFlag{
Name: "port,p",
Value: 3000,
Expand Down Expand Up @@ -78,6 +83,7 @@ func main() {
}

func MainAction(c *cli.Context) {
laddr := c.GlobalString("laddr")
port := c.GlobalInt("port")
appPort := strconv.Itoa(c.GlobalInt("appPort"))
immediate = c.GlobalBool("immediate")
Expand All @@ -99,6 +105,7 @@ func MainAction(c *cli.Context) {
proxy := gin.NewProxy(builder, runner)

config := &gin.Config{
Laddr: laddr,
Port: port,
ProxyTo: "http://localhost:" + appPort,
}
Expand All @@ -108,7 +115,11 @@ func MainAction(c *cli.Context) {
logger.Fatal(err)
}

logger.Printf("listening on port %d\n", port)
if laddr != "" {
logger.Printf("listening at %s:%d\n", laddr, port)
} else {
logger.Printf("listening on port %d\n", port)
}

shutdown(runner)

Expand Down