Skip to content

Commit

Permalink
Add flag to specify custom address
Browse files Browse the repository at this point in the history
  • Loading branch information
RadhiFadlillah committed Aug 27, 2019
1 parent c22f904 commit 806a3cf
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 63 deletions.
4 changes: 3 additions & 1 deletion internal/cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ func serveCmd() *cobra.Command {
}

cmd.Flags().IntP("port", "p", 8080, "Port that used by server")
cmd.Flags().StringP("address", "a", "", "Address the server listens to")

return cmd
}

func serveHandler(cmd *cobra.Command, args []string) {
port, _ := cmd.Flags().GetInt("port")
address, _ := cmd.Flags().GetString("address")

err := webserver.ServeApp(db, dataDir, port)
err := webserver.ServeApp(db, dataDir, address, port)
if err != nil {
logrus.Fatalf("Server error: %v\n", err)
}
Expand Down
120 changes: 60 additions & 60 deletions internal/webserver/assets-prod.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions internal/webserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
var httpClient = &http.Client{Timeout: time.Minute}

// ServeApp serves wb interface in specified port
func ServeApp(DB database.DB, dataDir string, port int) error {
func ServeApp(DB database.DB, dataDir string, address string, port int) error {
// Create handler
hdl := handler{
DB: DB,
Expand Down Expand Up @@ -68,7 +68,7 @@ func ServeApp(DB database.DB, dataDir string, port int) error {
}

// Create server
url := fmt.Sprintf(":%d", port)
url := fmt.Sprintf("%s:%d", address, port)
svr := &http.Server{
Addr: url,
Handler: router,
Expand Down

0 comments on commit 806a3cf

Please sign in to comment.