diff --git a/Dockerfile b/Dockerfile index 2f3a025..7e55887 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,6 +23,7 @@ COPY --from=build /app/static /app/static RUN mkdir -p /app/data && chown -R app:app /app EXPOSE 8002 +ENV HOST=0.0.0.0 ENV PORT=8002 USER app diff --git a/README.md b/README.md index 38cfbe3..56c6701 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ Enterprise-style Scrum Poker application using Go, Gin, and SSE for real-time ro ## Environment Variables +- `HOST`: server host/interface to bind (default all interfaces, equivalent to `0.0.0.0`) - `PORT`: server port (default `8002`) - `DATA_PATH`: directory for room JSON files (default `./data`) @@ -52,6 +53,13 @@ go run ./src Open `http://localhost:8002`. +To bind explicitly: + +```bash +HOST=localhost PORT=8002 go run ./src +HOST=0.0.0.0 PORT=8002 go run ./src +``` + ## Docker Build: diff --git a/src/config/config.go b/src/config/config.go index 96009a9..0cbdcee 100644 --- a/src/config/config.go +++ b/src/config/config.go @@ -3,11 +3,17 @@ package config import "os" type Config struct { + Host string Port string DataPath string } func Load() Config { + host := os.Getenv("HOST") + if host == "" { + host = "0.0.0.0" + } + port := os.Getenv("PORT") if port == "" { port = "8002" @@ -19,6 +25,7 @@ func Load() Config { } return Config{ + Host: host, Port: port, DataPath: dataPath, } diff --git a/src/main.go b/src/main.go index b5a35de..b25ed39 100644 --- a/src/main.go +++ b/src/main.go @@ -2,6 +2,7 @@ package main import ( "log" + "net" "scrum-solitare/src/config" "scrum-solitare/src/handlers" @@ -21,7 +22,7 @@ func main() { rooms := handlers.NewRoomAPIHandler(manager) router := server.NewRouter(pages, rooms) - if err := router.Run(":" + cfg.Port); err != nil { + if err := router.Run(net.JoinHostPort(cfg.Host, cfg.Port)); err != nil { log.Fatalf("server failed to start: %v", err) } }