Skip to content

Commit

Permalink
refac: move production mode to env
Browse files Browse the repository at this point in the history
  • Loading branch information
EjembiEmmanuel committed Aug 29, 2024
1 parent e58da42 commit 358bb81
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
4 changes: 4 additions & 0 deletions backend/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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/
7 changes: 6 additions & 1 deletion backend/config/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion backend/core/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package core
import (
"fmt"
"net/http"
"os"
"sync"

"github.com/gorilla/websocket"
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 358bb81

Please sign in to comment.