From 6a53bd9c80aa82b07e08140c300824a70bb75852 Mon Sep 17 00:00:00 2001 From: alessio Date: Tue, 8 Aug 2017 01:07:18 +0200 Subject: [PATCH] server startup fixed --- realize.go | 1 + server/main.go | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/realize.go b/realize.go index a6721a9..5f9cb92 100644 --- a/realize.go +++ b/realize.go @@ -115,6 +115,7 @@ func main() { &cli.BoolFlag{Name: "build", Aliases: []string{"b"}, Value: false, Usage: "Enable go build."}, &cli.BoolFlag{Name: "legacy", Aliases: []string{"l"}, Value: false, Usage: "Watch by polling instead of Watch by fsnotify."}, &cli.BoolFlag{Name: "server", Aliases: []string{"s"}, Value: false, Usage: "Enable server and open into the default browser."}, + &cli.BoolFlag{Name: "open", Aliases: []string{"o"}, Value: false, Usage: "Open server directly in the default browser."}, &cli.BoolFlag{Name: "no-run", Aliases: []string{"nr"}, Value: false, Usage: "Disable go run"}, &cli.BoolFlag{Name: "no-install", Aliases: []string{"ni"}, Value: false, Usage: "Disable go install"}, &cli.BoolFlag{Name: "no-config", Aliases: []string{"nc"}, Value: false, Usage: "Ignore existing configurations."}, diff --git a/server/main.go b/server/main.go index 2075e1c..105c7c4 100644 --- a/server/main.go +++ b/server/main.go @@ -52,7 +52,14 @@ func render(c echo.Context, path string, mime int) error { // Start the web server func (s *Server) Start(p *cli.Context) (err error) { - if s.Server.Status || p.Bool("server") { + if p.Bool("server"){ + s.Server.Status = p.Bool("server") + } + if p.Bool("open") { + s.Server.Open = p.Bool("open") + } + + if s.Server.Status { e := echo.New() e.Use(middleware.GzipWithConfig(middleware.GzipConfig{ Level: 2, @@ -110,7 +117,7 @@ func (s *Server) Start(p *cli.Context) (err error) { e.GET("/ws", s.projects) go e.Start(string(s.Settings.Server.Host) + ":" + strconv.Itoa(s.Settings.Server.Port)) - if s.Open || p.Bool("open") { + if s.Open { _, err = Open("http://" + string(s.Settings.Server.Host) + ":" + strconv.Itoa(s.Settings.Server.Port)) if err != nil { return err