diff --git a/.env.example b/.env.example index 1a8a094..3aa18fb 100644 --- a/.env.example +++ b/.env.example @@ -6,11 +6,12 @@ DATABASE_URL=postgres://surprise:surprise_dev_password@localhost:5432/surprise?s # SQLITE_PATH=./data/surprise.db PORT=8080 -API_URL=http://localhost:8080 CORS_ORIGIN=http://localhost:5173,http://127.0.0.1:5173 + SESSION_SECRET=local-development-session-secret-change-me COOKIE_SECURE=false +# ── MinIO / Storage ── STORAGE_ENDPOINT=localhost:9000 STORAGE_PUBLIC_ENDPOINT= STORAGE_ACCESS_KEY=minioadmin @@ -19,5 +20,12 @@ STORAGE_BUCKET=gallery-media STORAGE_USE_SSL=false MINIO_API_PORT=9000 MINIO_CONSOLE_PORT=9001 +NGINX_PORT=8099 -VITE_API_BASE_URL=http://localhost:8080 \ No newline at end of file +# ── Frontend (when running dev, not behind the nginx proxy) ── +# VITE_API_BASE_URL=http://localhost:8080 + +# ── Production ── +# NPM points to the nginx container (sndit-nginx:8099) which proxies: +# /api/* → sndit-api:8080 +# /* → sndit-frontend:80 \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 4e2eb80..b6a14d4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,6 +3,8 @@ services: image: postgres:16-alpine container_name: sndit-postgres restart: unless-stopped + networks: + - scoobydoo environment: POSTGRES_DB: surprise POSTGRES_USER: surprise @@ -22,6 +24,8 @@ services: image: minio/minio:latest container_name: sndit-minio restart: unless-stopped + networks: + - scoobydoo command: server /data --console-address ":9001" environment: MINIO_ROOT_USER: ${STORAGE_ACCESS_KEY:-minioadmin} @@ -42,13 +46,14 @@ services: build: ./backend container_name: sndit-api restart: unless-stopped + networks: + - scoobydoo ports: - "${PORT:-8080}:8080" environment: DB_DRIVER: postgres DATABASE_URL: postgres://surprise:surprise_dev_password@postgres:5432/surprise?sslmode=disable PORT: "8080" - CORS_ORIGIN: "http://localhost:8081" SESSION_SECRET: "${SESSION_SECRET:-docker-compose-session-secret-change-me}" COOKIE_SECURE: "${COOKIE_SECURE:-false}" STORAGE_ENDPOINT: "minio:9000" @@ -66,6 +71,8 @@ services: migrate: build: ./backend container_name: sndit-migrate + networks: + - scoobydoo command: ["migrate", "-dir", "/migrations"] environment: DB_DRIVER: postgres @@ -79,6 +86,8 @@ services: seed: build: ./backend container_name: sndit-seed + networks: + - scoobydoo command: ["seed"] environment: DB_DRIVER: postgres @@ -91,14 +100,32 @@ services: build: context: ./frontend args: - VITE_API_BASE_URL: "" + VITE_API_BASE_URL: "${VITE_API_BASE_URL}" container_name: sndit-frontend restart: unless-stopped - ports: - - "${FRONTEND_PORT:-8081}:80" + networks: + - scoobydoo depends_on: - api + nginx: + image: nginx:alpine + container_name: sndit-nginx + restart: unless-stopped + networks: + - scoobydoo + ports: + - "${NGINX_PORT:-8099}:80" + volumes: + - ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf:ro + depends_on: + - frontend + - api + volumes: postgres_data: - minio_data: \ No newline at end of file + minio_data: + +networks: + scoobydoo: + external: true \ No newline at end of file diff --git a/frontend/nginx.conf b/frontend/nginx.conf index d738586..6d396d0 100644 --- a/frontend/nginx.conf +++ b/frontend/nginx.conf @@ -2,24 +2,6 @@ server { listen 80; root /usr/share/nginx/html; - location /api/ { - proxy_pass http://api:8080/api/; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto $scheme; - } - - location /swagger/ { - proxy_pass http://api:8080/swagger/; - proxy_set_header Host $host; - } - - location /health { - proxy_pass http://api:8080/health; - proxy_set_header Host $host; - } - location / { try_files $uri /index.html; } diff --git a/frontend/src/lib/api.ts b/frontend/src/lib/api.ts index f6d93a2..038092a 100644 --- a/frontend/src/lib/api.ts +++ b/frontend/src/lib/api.ts @@ -7,10 +7,7 @@ import type { PublicGallery, } from '../types/gallery'; -const apiBaseUrl = (import.meta.env.VITE_API_BASE_URL || 'http://localhost:8080').replace( - /\/$/, - '', -); +const apiBaseUrl = (import.meta.env.VITE_API_BASE_URL || '').replace(/\/$/, ''); export class ApiError extends Error { readonly status: number; diff --git a/nginx/nginx.conf b/nginx/nginx.conf new file mode 100644 index 0000000..dc0fc2f --- /dev/null +++ b/nginx/nginx.conf @@ -0,0 +1,29 @@ +server { + listen 80; + + location /api/ { + proxy_pass http://sndit-api:8080/api/; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + + location /swagger/ { + proxy_pass http://sndit-api:8080/swagger/; + proxy_set_header Host $host; + } + + location /health { + proxy_pass http://sndit-api:8080/health; + proxy_set_header Host $host; + } + + location / { + proxy_pass http://sndit-frontend:80/; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } +} \ No newline at end of file