HOST Variable
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user