From f172cd6f934c0ae913daeaafabea90188ca6e2a1 Mon Sep 17 00:00:00 2001 From: Przemyslaw Kadej Date: Sat, 6 Jun 2026 16:39:09 +0200 Subject: [PATCH] updates --- backend/cmd/server/main.go | 23 ++++++++++++++++++++++- docker-compose.yml | 16 ++++++++++++++-- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/backend/cmd/server/main.go b/backend/cmd/server/main.go index 21f0548..2f2fb62 100644 --- a/backend/cmd/server/main.go +++ b/backend/cmd/server/main.go @@ -22,7 +22,24 @@ func main() { dsn := os.Getenv("DATABASE_URL") if dsn == "" { - dsn = "postgres://dropzone:dropzone@localhost:15432/dropzone?sslmode=disable" + host := os.Getenv("DB_HOST") + if host == "" { + host = "localhost" + } + port := os.Getenv("DB_PORT") + if port == "" { + port = "15432" + } + name := os.Getenv("DB_NAME") + if name == "" { + name = "dropzone" + } + user := os.Getenv("DB_USER") + if user == "" { + user = "dropzone" + } + pass := os.Getenv("DB_PASSWORD") + dsn = fmt.Sprintf("postgres://%s:%s@%s:%s/%s?sslmode=disable", user, pass, host, port, name) } jwtSecret := os.Getenv("JWT_SECRET") if jwtSecret == "" { @@ -52,6 +69,10 @@ func main() { r.Use(chimiddleware.Logger) r.Use(chimiddleware.Recoverer) + r.Get("/api/health", func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusOK) + }) + // Public endpoints r.Post("/api/auth/login", auth.NewLoginHandler(db, jwtSecret)) r.Get("/api/files/public", files.PublicListHandler(diskRoot)) diff --git a/docker-compose.yml b/docker-compose.yml index c596d08..ea9fd70 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,6 +14,11 @@ services: volumes: - postgres_data:/var/lib/postgresql/data - ./postgres/init:/docker-entrypoint-initdb.d:ro + healthcheck: + test: ["CMD-SHELL", "pg_isready -U ${DB_USER} -d ${DB_NAME}"] + interval: 5s + timeout: 5s + retries: 10 networks: - internal @@ -36,7 +41,13 @@ services: volumes: - ${DISK_ROOT}:${DISK_ROOT} depends_on: - - postgres + postgres: + condition: service_healthy + healthcheck: + test: ["CMD-SHELL", "wget -qO- http://localhost:8080/api/health || exit 1"] + interval: 5s + timeout: 5s + retries: 10 networks: - internal @@ -55,7 +66,8 @@ services: - ./nginx/templates:/etc/nginx/templates:ro - ${DISK_ROOT}:${DISK_ROOT}:ro depends_on: - - backend + backend: + condition: service_healthy networks: - internal - external