modifeid redis and app

This commit is contained in:
2025-02-06 15:44:16 +00:00
parent 2a47e00255
commit 82b1c4a77a
3 changed files with 9 additions and 10 deletions

View File

@@ -16,15 +16,15 @@ app = FastAPI()
# Secret API Key # Secret API Key
SECRET_PHRASE = os.getenv("API_SECRET", "my_secret_key") SECRET_PHRASE = os.getenv("API_SECRET", "my_secret_key")
# Use the Redis password from the environment variable
REDIS_URL = os.getenv("REDIS_URL", "redis://:my_redis_password@redis:6379")
redis_client = redis.from_url(REDIS_URL)
# Use the Redis password from the environment variable
REDIS_URL = os.getenv("REDIS_URL", "redis://redis:6379/0")
@app.on_event("startup") @app.on_event("startup")
async def startup(): async def startup():
"""Initialize FastAPI Limiter.""" """Initialize FastAPI Limiter with async Redis connection."""
await FastAPILimiter.init(redis_client) redis = await aioredis.from_url(REDIS_URL, decode_responses=True)
await FastAPILimiter.init(redis)
# Setup Static Files for Documentation # Setup Static Files for Documentation
app.mount("/", StaticFiles(directory="app/docs", html=True), name="docs") app.mount("/", StaticFiles(directory="app/docs", html=True), name="docs")

View File

@@ -5,10 +5,10 @@ services:
build: . build: .
container_name: screenshot-api container_name: screenshot-api
ports: ports:
- "80:80" - "8990:80"
environment: environment:
- API_SECRET=kokeserver - API_SECRET=my_secret_key
- REDIS_URL=redis://:my_redis_password@redis:6379 - REDIS_URL=redis://redis:6379/0
depends_on: depends_on:
- redis - redis
networks: networks:
@@ -20,7 +20,6 @@ services:
restart: always restart: always
ports: ports:
- "6379:6379" - "6379:6379"
command: redis-server --requirepass my_redis_password
networks: networks:
- screenshot-network - screenshot-network

View File

@@ -2,4 +2,4 @@ fastapi
uvicorn uvicorn
playwright playwright
fastapi-limiter fastapi-limiter
redis aioredis