Skip to content

Commit

Permalink
Possibility to specify listening IP (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
fiksn committed Sep 30, 2021
1 parent 561610a commit 3200622
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions lnme.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"github.com/labstack/echo/v4/middleware"
)

const DEFAULT_LISTEN = ":1323"

// Middleware for request limited to prevent too many requests
// TODO: move to file
func LimitMiddleware(lmt *limiter.Limiter) echo.MiddlewareFunc {
Expand Down Expand Up @@ -185,10 +187,24 @@ func main() {
})

port := cfg.String("port")
// Special case for PORT instead of LNME_PORT due to cloud-providers
if os.Getenv("PORT") != "" {
port = os.Getenv("PORT")
}
e.Logger.Fatal(e.Start(":" + port))
listen := cfg.String("listen")
if listen != "" && port != "" {
log.Fatalf("Port and listen options are mutually exclusive, please just use listen.")
}
if listen == "" {
if port != "" {
stdOutLogger.Printf("Please use listen instead of deprecated port setting.")
listen = fmt.Sprintf(":%s", port)
} else {
listen = DEFAULT_LISTEN
}
}

e.Logger.Fatal(e.Start(listen))
}

func LoadConfig() *koanf.Koanf {
Expand All @@ -203,7 +219,8 @@ func LoadConfig() *koanf.Koanf {
f.Bool("disable-cors", false, "Disable CORS headers.")
f.Float64("request-limit", 5, "Request limit per second.")
f.String("static-path", "", "Path to a static assets directory.")
f.String("port", "1323", "Port to bind on.")
f.String("port", "", "Port to bind on (deprecated - use listen).")
f.String("listen", "", fmt.Sprintf("Address to bind on. (default \"%s\")", DEFAULT_LISTEN))
var configPath string
f.StringVar(&configPath, "config", "config.toml", "Path to a .toml config file.")
f.Parse(os.Args[1:])
Expand Down

0 comments on commit 3200622

Please sign in to comment.