Add support for serving static files from DATA_FILES_DIR
Introduce a new environment variable, `DATA_FILES_DIR`, for configuring static file storage. Updated `docker-compose` files to mount the host directory and propagate the variable. Implemented FastAPI `StaticFiles` to serve files from this directory under the `/files` route.
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
from pydantic_settings import BaseSettings
|
from pydantic_settings import BaseSettings
|
||||||
from typing import Optional, List
|
from typing import Optional, List
|
||||||
|
|
||||||
@@ -6,6 +8,7 @@ class Settings(BaseSettings):
|
|||||||
PROJECT_NAME: str = "EventSpace"
|
PROJECT_NAME: str = "EventSpace"
|
||||||
VERSION: str = "1.0.0"
|
VERSION: str = "1.0.0"
|
||||||
API_V1_STR: str = "/api/v1"
|
API_V1_STR: str = "/api/v1"
|
||||||
|
DATA_FILES_DIR: str = os.getenv('DATA_FILES_DIR', 'data/')
|
||||||
|
|
||||||
# Database configuration
|
# Database configuration
|
||||||
POSTGRES_USER: str = "postgres"
|
POSTGRES_USER: str = "postgres"
|
||||||
@@ -14,7 +17,6 @@ class Settings(BaseSettings):
|
|||||||
POSTGRES_PORT: str = "5432"
|
POSTGRES_PORT: str = "5432"
|
||||||
POSTGRES_DB: str = "eventspace"
|
POSTGRES_DB: str = "eventspace"
|
||||||
DATABASE_URL: Optional[str] = None
|
DATABASE_URL: Optional[str] = None
|
||||||
REFRESH_TOKEN_EXPIRE_DAYS: int = 60
|
|
||||||
db_pool_size: int = 20 # Default connection pool size
|
db_pool_size: int = 20 # Default connection pool size
|
||||||
db_max_overflow: int = 50 # Maximum overflow connections
|
db_max_overflow: int = 50 # Maximum overflow connections
|
||||||
db_pool_timeout: int = 30 # Seconds to wait for a connection
|
db_pool_timeout: int = 30 # Seconds to wait for a connection
|
||||||
@@ -26,6 +28,8 @@ class Settings(BaseSettings):
|
|||||||
sql_echo_timing: bool = False # Log query execution times
|
sql_echo_timing: bool = False # Log query execution times
|
||||||
slow_query_threshold: float = 0.5 # Log queries taking longer than this
|
slow_query_threshold: float = 0.5 # Log queries taking longer than this
|
||||||
|
|
||||||
|
REFRESH_TOKEN_EXPIRE_DAYS: int = 60
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def database_url(self) -> str:
|
def database_url(self) -> str:
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
|||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
from fastapi.middleware.cors import CORSMiddleware
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
from fastapi.responses import HTMLResponse
|
from fastapi.responses import HTMLResponse
|
||||||
|
from fastapi.staticfiles import StaticFiles
|
||||||
|
|
||||||
from app.api.router import api_router
|
from app.api.router import api_router
|
||||||
from app.core.config import settings
|
from app.core.config import settings
|
||||||
@@ -46,3 +47,4 @@ async def root():
|
|||||||
|
|
||||||
|
|
||||||
app.include_router(api_router, prefix=settings.API_V1_STR)
|
app.include_router(api_router, prefix=settings.API_V1_STR)
|
||||||
|
app.mount("/files", StaticFiles(directory=settings.DATA_FILES_DIR), name="static")
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ services:
|
|||||||
- ./backend:/app
|
- ./backend:/app
|
||||||
- ./uploads:/app/uploads
|
- ./uploads:/app/uploads
|
||||||
- backend_dev_modules:/app/.venv
|
- backend_dev_modules:/app/.venv
|
||||||
|
- ${HOST_DATA_FILES_DIR}:${DATA_FILES_DIR}
|
||||||
ports:
|
ports:
|
||||||
- "8000:8000"
|
- "8000:8000"
|
||||||
env_file:
|
env_file:
|
||||||
@@ -34,6 +35,8 @@ services:
|
|||||||
- DATABASE_URL=${DATABASE_URL}
|
- DATABASE_URL=${DATABASE_URL}
|
||||||
- SECRET_KEY=${SECRET_KEY}
|
- SECRET_KEY=${SECRET_KEY}
|
||||||
- ENVIRONMENT=development
|
- ENVIRONMENT=development
|
||||||
|
- DATA_FILES_DIR=${DATA_FILES_DIR}
|
||||||
|
- HOST_DATA_FILES_DIR=${HOST_DATA_FILES_DIR}
|
||||||
- DEBUG=true
|
- DEBUG=true
|
||||||
- BACKEND_CORS_ORIGINS=${BACKEND_CORS_ORIGINS}
|
- BACKEND_CORS_ORIGINS=${BACKEND_CORS_ORIGINS}
|
||||||
depends_on:
|
depends_on:
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ services:
|
|||||||
environment:
|
environment:
|
||||||
- DATABASE_URL=${DATABASE_URL}
|
- DATABASE_URL=${DATABASE_URL}
|
||||||
- SECRET_KEY=${SECRET_KEY}
|
- SECRET_KEY=${SECRET_KEY}
|
||||||
|
- DATA_FILES_DIR=${DATA_FILES_DIR}
|
||||||
|
- HOST_DATA_FILES_DIR=${HOST_DATA_FILES_DIR}
|
||||||
- ENVIRONMENT=production
|
- ENVIRONMENT=production
|
||||||
- DEBUG=false
|
- DEBUG=false
|
||||||
- BACKEND_CORS_ORIGINS=${BACKEND_CORS_ORIGINS}
|
- BACKEND_CORS_ORIGINS=${BACKEND_CORS_ORIGINS}
|
||||||
@@ -35,6 +37,8 @@ services:
|
|||||||
networks:
|
networks:
|
||||||
- app-network
|
- app-network
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
volumes:
|
||||||
|
- ${HOST_DATA_FILES_DIR}:${DATA_FILES_DIR}
|
||||||
|
|
||||||
frontend:
|
frontend:
|
||||||
build:
|
build:
|
||||||
|
|||||||
Reference in New Issue
Block a user