Browse Source

updates

master
Przemyslaw Kadej 3 weeks ago
parent
commit
f172cd6f93
  1. 23
      backend/cmd/server/main.go
  2. 16
      docker-compose.yml

23
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))

16
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

Loading…
Cancel
Save