Skip to content
Open
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 {
Bind string `json:"bind"`
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.Bind, config.Port))
if err != nil {
return err
}
Expand Down
23 changes: 21 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: ".",
Expand All @@ -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{
{
Expand Down Expand Up @@ -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,
}
Expand All @@ -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)

Expand Down