cmd: CMD option for port number of gogs web to prevent first time run conflict

- routers: use new binding convention to simplify code
- templates: able to set HTTP port number in install page
This commit is contained in:
Unknwon 2015-02-01 12:41:03 -05:00
parent 3d9cda2d98
commit b293b6eaa6
10 changed files with 133 additions and 122 deletions

View file

@ -53,7 +53,9 @@ var CmdWeb = cli.Command{
Description: `Gogs web server is the only thing you need to run,
and it takes care of all the other things for you`,
Action: runWeb,
Flags: []cli.Flag{},
Flags: []cli.Flag{
cli.StringFlag{"port, p", "3000", "Temporary port number to prevent conflict", ""},
},
}
type VerChecker struct {
@ -162,7 +164,7 @@ func newMacaron() *macaron.Macaron {
return m
}
func runWeb(*cli.Context) {
func runWeb(ctx *cli.Context) {
routers.GlobalInit()
checkVersion()
@ -179,9 +181,9 @@ func runWeb(*cli.Context) {
// Routers.
m.Get("/", ignSignIn, routers.Home)
m.Get("/explore", ignSignIn, routers.Explore)
// FIXME: when i'm binding form here???
m.Get("/install", bindIgnErr(auth.InstallForm{}), routers.Install)
m.Post("/install", bindIgnErr(auth.InstallForm{}), routers.InstallPost)
m.Combo("/install", routers.InstallInit).
Get(routers.Install).
Post(bindIgnErr(auth.InstallForm{}), routers.InstallPost)
m.Group("", func() {
m.Get("/pulls", user.Pulls)
m.Get("/issues", user.Issues)
@ -460,6 +462,12 @@ func runWeb(*cli.Context) {
// Not found handler.
m.NotFound(routers.NotFound)
// Flag for port number in case first time run conflict.
if ctx.IsSet("port") {
setting.AppUrl = strings.Replace(setting.AppUrl, setting.HttpPort, ctx.String("port"), 1)
setting.HttpPort = ctx.String("port")
}
var err error
listenAddr := fmt.Sprintf("%s:%s", setting.HttpAddr, setting.HttpPort)
log.Info("Listen: %v://%s%s", setting.Protocol, listenAddr, setting.AppSubUrl)