diff --git a/lib/config.go b/lib/config.go index b69b14f..9d2a3c5 100644 --- a/lib/config.go +++ b/lib/config.go @@ -7,6 +7,7 @@ import ( ) type Config struct { + Bind string `json:"bind"` Port int `json:"port"` ProxyTo string `json:"proxy_to"` } diff --git a/lib/proxy.go b/lib/proxy.go index 316b740..370c3fb 100644 --- a/lib/proxy.go +++ b/lib/proxy.go @@ -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.Bind, config.Port)) if err != nil { return err } diff --git a/main.go b/main.go index e9310a0..1073137 100644 --- a/main.go +++ b/main.go @@ -45,6 +45,11 @@ func main() { Value: "gin-bin", Usage: "name of generated binary file", }, + cli.StringFlag{ + Name: "bind,n", + Value: "", + Usage: "Interface to bind for the Gin proxy server", + }, cli.StringFlag{ Name: "path,t", Value: ".", @@ -58,6 +63,11 @@ func main() { Name: "godep,g", Usage: "use godep when building", }, + cli.StringFlag{ + Name: "build,d", + Value: "", + Usage: "Path to build files from (defaults to same value as --path)", + }, } app.Commands = []cli.Command{ { @@ -93,12 +103,17 @@ func MainAction(c *cli.Context) { logger.Fatal(err) } - builder := gin.NewBuilder(c.GlobalString("path"), c.GlobalString("bin"), c.GlobalBool("godep")) + buildPath := c.GlobalString("build") + if buildPath == "" { + buildPath = c.GlobalString("path") + } + builder := gin.NewBuilder(buildPath, c.GlobalString("bin"), c.GlobalBool("godep")) runner := gin.NewRunner(filepath.Join(wd, builder.Binary()), c.Args()...) runner.SetWriter(os.Stdout) proxy := gin.NewProxy(builder, runner) config := &gin.Config{ + Bind: c.GlobalString("bind"), Port: port, ProxyTo: "http://localhost:" + appPort, } @@ -108,7 +123,11 @@ func MainAction(c *cli.Context) { logger.Fatal(err) } - logger.Printf("listening on port %d\n", port) + if config.Bind != "" { + logger.Printf("listening on %s:%d\n", config.Bind, port) + } else { + logger.Printf("listening on port %d\n", port) + } shutdown(runner)