4.7 KiB
4.7 KiB
Netflix Scraper API - Operasyon Dokümantasyonu
Hızlı Başlangıç
Gereksinimler
- Docker & Docker Compose
- Node.js 20+ (local development için)
Tek Komut ile Başlatma (Development)
# .env dosyasını oluştur
cp .env.example .env
# .env dosyasını düzenle
nano .env
# Başlat
docker compose -f docker-compose.dev.yml up --build
Hepsi bu kadar! Uygulama şu adreste çalışacak: http://localhost:3000
Ortamlar
Development
docker compose -f docker-compose.dev.yml up --build
Özellikler:
- Hot reload aktif
- Tüm loglar görünür
- Debug modu
Production
docker compose up --build -d
Özellikler:
- Multi-stage build
- Non-root user
- Minimal image
- Production optimizations
Environment Değişkenleri
.env Dosyası
# === Server ===
PORT=3000
NODE_ENV=development
# === PostgreSQL ===
POSTGRES_HOST=postgres
POSTGRES_PORT=5432
POSTGRES_USER=postgres
POSTGRES_PASSWORD=your-secure-password
POSTGRES_DB=netflix_scraper
# === Redis ===
REDIS_HOST=redis
REDIS_PORT=6379
REDIS_TTL_SECONDS=604800
# === Rate Limiting ===
RATE_LIMIT_WINDOW_MS=60000
RATE_LIMIT_MAX_REQUESTS=30
# === API Keys ===
API_KEY_WEB=web-key-change-me
API_KEY_MOBILE=mobile-key-change-me
API_KEY_ADMIN=admin-key-secret
Değişken Açıklamaları
| Değişken | Açıklama | Varsayılan |
|---|---|---|
PORT |
Sunucu portu | 3000 |
NODE_ENV |
Ortam (development/production) | development |
REDIS_TTL_SECONDS |
Cache süresi (saniye) | 604800 (7 gün) |
RATE_LIMIT_WINDOW_MS |
Rate limit penceresi (ms) | 60000 (1 dk) |
RATE_LIMIT_MAX_REQUESTS |
Max istek sayısı | 30 |
Migration
Migration'lar otomatik olarak container başlatılırken çalışır. Manuel çalıştırmak için:
# Container içinde
docker compose exec app npx prisma migrate deploy
# Local
npx prisma migrate deploy
Yeni Migration Oluşturma
npx prisma migrate dev --name description_of_change
Loglama
Tüm loglar JSON formatında structured logging ile yazılır.
Log Seviyeleri
| Seviye | Açıklama |
|---|---|
debug |
Detaylı debug bilgisi |
info |
Genel bilgi |
warn |
Uyarı |
error |
Hata |
Log Formatı
{
"timestamp": "2025-02-27T10:00:00.000Z",
"level": "info",
"message": "Server started",
"service": "netflix-scraper-api",
"port": 3000
}
Log Seviyesi Ayarlama
LOG_LEVEL=debug
Health Check
Endpoints
GET /health- Basit sağlık kontrolüGET /ready- Bağımlılık kontrolü (DB + Redis)
Docker Health Check
Container'lar otomatik health check ile izlenir:
healthcheck:
test: ["CMD", "wget", "--spider", "http://localhost:3000/health"]
interval: 30s
timeout: 10s
retries: 3
Troubleshooting
Database Bağlantı Hatası
Error: Can't reach database server
Çözüm:
- PostgreSQL container'ın çalıştığını kontrol et
POSTGRES_HOSTdeğerini kontrol et (docker'dapostgresolmalı)- Health check'i bekle:
docker compose logs postgres
Redis Bağlantı Hatası
Error: Redis connection failed
Çözüm:
- Redis container'ın çalıştığını kontrol et
REDIS_HOSTdeğerini kontrol et
Migration Hatası
Error: P3005: The database schema is not empty
Çözüm:
# Veritabanını sıfırla
docker compose down -v
docker compose up --build
Port Kullanımda Hatası
Error: port is already allocated
Çözüm:
# Hangi process kullanıyor
lsof -i :3000
# Process'i durdur
kill -9 <PID>
Yararlı Komutlar
Container Yönetimi
# Container'ları durdur
docker compose down
# Container'ları sil (volumes dahil)
docker compose down -v
# Logları görüntüle
docker compose logs -f app
# Container içine gir
docker compose exec app sh
Database İşlemleri
# Prisma studio aç
docker compose exec app npx prisma studio
# Database schema görüntüle
docker compose exec app npx prisma db pull
# Seed çalıştır
docker compose exec app npm run prisma:seed
Redis İşlemleri
# Redis CLI
docker compose exec redis redis-cli
# Tüm cache'i temizle
docker compose exec redis redis-cli FLUSHALL
Backup & Restore
PostgreSQL Backup
docker compose exec postgres pg_dump -U postgres netflix_scraper > backup.sql
PostgreSQL Restore
cat backup.sql | docker compose exec -T postgres psql -U postgres netflix_scraper
Monitoring (Opsiyonel)
Metrics Endpoint (Yakında)
GET /metrics
Prometheus uyumlu metrics döndürür.