Skip to content
This repository has been archived by the owner on May 23, 2022. It is now read-only.

Commit

Permalink
confetti-framework/confetti#131 fix listen to default host
Browse files Browse the repository at this point in the history
  • Loading branch information
Reindert Vetter committed May 5, 2021
1 parent 1fb4cfb commit 46764dd
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions console/app_serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ func (s AppServe) Description() string {

// Handle contains the logic of the command
func (s AppServe) Handle(c inter.Cli) inter.ExitCode {
name := c.App().Make("config.App.Name").(string)
appProvider := c.App().Make(inter.AppProvider).(func() inter.App)
app := c.App()
name := app.Make("config.App.Name").(string)
appProvider := app.Make(inter.AppProvider).(func() inter.App)

// This bootstraps the framework and gets it ready for use, then it will load up
// this application so that we can run it and send the responses back to the
Expand All @@ -37,9 +38,9 @@ func (s AppServe) Handle(c inter.Cli) inter.ExitCode {
http.HandleHttpKernel(app, response, request)
}

c.Line("\u001B[32mStarting %s server:\u001B[0m http://%s", name, s.getAddr(c.App()))
c.Line("\u001B[32mStarting %s server:\u001B[0m %s", name, s.getHumanAddr(app))
server := &net.Server{
Addr: s.getAddr(c.App()),
Addr: s.getListenAddr(app),
Handler: net.HandlerFunc(handler),
WriteTimeout: 30 * time.Second,
ReadTimeout: 30 * time.Second,
Expand Down Expand Up @@ -73,9 +74,16 @@ func (s AppServe) getHostAddr(app inter.App) string {
if err == nil {
return h.(string)
}
return "127.0.0.1"
return ""
}

func (s AppServe) getAddr(app inter.App) string {
func (s AppServe) getListenAddr(app inter.App) string {
return s.getHostAddr(app) + ":" + s.getPortAddr(app)
}

func (s AppServe) getHumanAddr(app inter.App) interface{} {
if s.getHostAddr(app) != "" {
return s.getHostAddr(app) + ":" + s.getPortAddr(app)
}
return "http://localhost:" + s.getPortAddr(app)
}

0 comments on commit 46764dd

Please # to comment.