1
1
mirror of https://github.com/bumi/lntip synced 2025-06-17 02:05:35 +00:00

Possibility to specify listening IP (#17)

This commit is contained in:
Gregor Pogačnik 2021-09-30 18:07:43 +02:00 committed by GitHub
parent 561610a7b9
commit 3200622b97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

21
lnme.go
View File

@ -24,6 +24,8 @@ import (
"github.com/labstack/echo/v4/middleware" "github.com/labstack/echo/v4/middleware"
) )
const DEFAULT_LISTEN = ":1323"
// Middleware for request limited to prevent too many requests // Middleware for request limited to prevent too many requests
// TODO: move to file // TODO: move to file
func LimitMiddleware(lmt *limiter.Limiter) echo.MiddlewareFunc { func LimitMiddleware(lmt *limiter.Limiter) echo.MiddlewareFunc {
@ -185,10 +187,24 @@ func main() {
}) })
port := cfg.String("port") port := cfg.String("port")
// Special case for PORT instead of LNME_PORT due to cloud-providers
if os.Getenv("PORT") != "" { if os.Getenv("PORT") != "" {
port = 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 { func LoadConfig() *koanf.Koanf {
@ -203,7 +219,8 @@ func LoadConfig() *koanf.Koanf {
f.Bool("disable-cors", false, "Disable CORS headers.") f.Bool("disable-cors", false, "Disable CORS headers.")
f.Float64("request-limit", 5, "Request limit per second.") f.Float64("request-limit", 5, "Request limit per second.")
f.String("static-path", "", "Path to a static assets directory.") 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 var configPath string
f.StringVar(&configPath, "config", "config.toml", "Path to a .toml config file.") f.StringVar(&configPath, "config", "config.toml", "Path to a .toml config file.")
f.Parse(os.Args[1:]) f.Parse(os.Args[1:])