diff --git a/backend/.env.example b/backend/.env.example index 44f12674..deb0192a 100644 --- a/backend/.env.example +++ b/backend/.env.example @@ -10,3 +10,7 @@ POSTGRES_DATABASE=postgres BACKEND_HOST=localhost BACKEND_PORT=8082 CONSUMER_PORT=8081 + +PRODUCTION=false + +BACKEND_URL=https://backend-pixel.onrender.com/ \ No newline at end of file diff --git a/backend/config/backend.go b/backend/config/backend.go index 43d95bf4..63d22a6c 100644 --- a/backend/config/backend.go +++ b/backend/config/backend.go @@ -57,6 +57,11 @@ func LoadBackendConfig() (*BackendConfig, error) { return nil, fmt.Errorf("invalid BACKEND_PORT: %v", err) } + production, err := strconv.ParseBool(os.Getenv("PRODUCTION")) + if err != nil { + return nil, fmt.Errorf("invalid PRODUCTION mode: %v", err) + } + config := BackendConfig{ Host: os.Getenv("BACKEND_HOST"), Port: backendPort, @@ -79,7 +84,7 @@ func LoadBackendConfig() (*BackendConfig, error) { AddFactionTemplateDevnet: "../scripts/add_faction_template.sh", RemoveFactionTemplateDevnet: "../scripts/remove_faction_template.sh", }, - Production: false, + Production: production, WebSocket: WebSocketConfig{ ReadBufferSize: 1024, WriteBufferSize: 1024, diff --git a/backend/core/backend.go b/backend/core/backend.go index 9b734fe4..5ab79d23 100644 --- a/backend/core/backend.go +++ b/backend/core/backend.go @@ -3,6 +3,7 @@ package core import ( "fmt" "net/http" + "os" "sync" "github.com/gorilla/websocket" @@ -40,7 +41,7 @@ func (b *Backend) Start(port int) { func (b *Backend) GetBackendUrl() string { if b.BackendConfig.Production { - return "https://backend-pixel.onrender.com/" + return os.Getenv("BACKEND_URL") } else { return fmt.Sprintf("http://%s:%d", b.BackendConfig.Host, b.BackendConfig.Port) }