From f3ffa19ecfe27f33f25a5e66fe318a43a612f89a Mon Sep 17 00:00:00 2001 From: Blake Gentry Date: Thu, 2 May 2024 20:51:45 -0500 Subject: [PATCH] specify port with env --- .env.example | 1 + main.go | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.env.example b/.env.example index a506cad..3a17d15 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,4 @@ CORS_ORIGINS=http://localhost:5173,http://example.com DATABASE_URL=postgres://postgres:postgres@localhost:5432/your_db_name OTEL_ENABLED=false +PORT=8080 diff --git a/main.go b/main.go index a70b1c5..d0628eb 100644 --- a/main.go +++ b/main.go @@ -45,6 +45,10 @@ func initAndServe(ctx context.Context) int { corsOrigins := strings.Split(corsOriginString, ",") dbURL := mustEnv("DATABASE_URL") otelEnabled := os.Getenv("OTEL_ENABLED") == "true" + port := os.Getenv("PORT") + if port == "" { + port = "8080" + } frontendIndex, err := fs.Sub(ui.Index, "dist") if err != nil { @@ -93,7 +97,7 @@ func initAndServe(ctx context.Context) int { wrappedHandler := sloghttp.NewWithConfig(logger, config)(corsHandler.Handler(logHandler)) srv := &http.Server{ - Addr: ":8080", + Addr: ":" + port, Handler: wrappedHandler, ReadHeaderTimeout: 5 * time.Second, }