| 143 | } |
| 144 | |
| 145 | func MainAction(c *cli.Context) { |
| 146 | laddr := c.GlobalString("laddr") |
| 147 | port := c.GlobalInt("port") |
| 148 | all := c.GlobalBool("all") |
| 149 | appPort := strconv.Itoa(c.GlobalInt("appPort")) |
| 150 | immediate = c.GlobalBool("immediate") |
| 151 | keyFile := c.GlobalString("keyFile") |
| 152 | certFile := c.GlobalString("certFile") |
| 153 | logPrefix := c.GlobalString("logPrefix") |
| 154 | notifications = c.GlobalBool("notifications") |
| 155 | |
| 156 | logger.SetPrefix(fmt.Sprintf("[%s] ", logPrefix)) |
| 157 | |
| 158 | // Bootstrap the environment |
| 159 | envy.Bootstrap() |
| 160 | |
| 161 | // Set the PORT env |
| 162 | os.Setenv("PORT", appPort) |
| 163 | |
| 164 | wd, err := os.Getwd() |
| 165 | if err != nil { |
| 166 | logger.Fatal(err) |
| 167 | } |
| 168 | |
| 169 | buildArgs, err := shellwords.Parse(c.GlobalString("buildArgs")) |
| 170 | if err != nil { |
| 171 | logger.Fatal(err) |
| 172 | } |
| 173 | |
| 174 | buildPath := c.GlobalString("build") |
| 175 | if buildPath == "" { |
| 176 | buildPath = c.GlobalString("path") |
| 177 | } |
| 178 | builder := gin.NewBuilder(buildPath, c.GlobalString("bin"), c.GlobalBool("godep"), wd, buildArgs) |
| 179 | runner := gin.NewRunner(filepath.Join(wd, builder.Binary()), c.Args()...) |
| 180 | runner.SetWriter(os.Stdout) |
| 181 | proxy := gin.NewProxy(builder, runner) |
| 182 | |
| 183 | config := &gin.Config{ |
| 184 | Laddr: laddr, |
| 185 | Port: port, |
| 186 | ProxyTo: "http://localhost:" + appPort, |
| 187 | KeyFile: keyFile, |
| 188 | CertFile: certFile, |
| 189 | } |
| 190 | |
| 191 | err = proxy.Run(config) |
| 192 | if err != nil { |
| 193 | logger.Fatal(err) |
| 194 | } |
| 195 | |
| 196 | if laddr != "" { |
| 197 | logger.Printf("Listening at %s:%d\n", laddr, port) |
| 198 | } else { |
| 199 | logger.Printf("Listening on port %d\n", port) |
| 200 | } |
| 201 | |
| 202 | shutdown(runner) |