Skip to content

Commit

Permalink
specify port with env
Browse files Browse the repository at this point in the history
  • Loading branch information
bgentry committed May 3, 2024
1 parent cd5fd0c commit f3ffa19
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -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
6 changes: 5 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
}
Expand Down

0 comments on commit f3ffa19

Please sign in to comment.