ci: dockerise l'API + connexion DB et CORS configurables par env
- config.py: connexion SQL via DB_* (driver 18, auth SQL), fallback Windows local - main.py: origines CORS via CORS_ORIGINS - Dockerfile (python 3.12 + msodbcsql18) + workflow Gitea Actions (build/push image)
This commit is contained in:
@@ -7,6 +7,8 @@
|
||||
# Swagger : http://localhost:8000/docs
|
||||
# ============================================================
|
||||
|
||||
import os
|
||||
|
||||
from fastapi import FastAPI, HTTPException, Query
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from typing import Optional
|
||||
@@ -14,6 +16,14 @@ from datetime import date
|
||||
|
||||
from config import Config, get_cursor
|
||||
|
||||
# Origines autorisées : depuis CORS_ORIGINS (séparées par des virgules) en prod,
|
||||
# localhost par défaut en dev.
|
||||
CORS_ORIGINS = [
|
||||
o.strip()
|
||||
for o in os.getenv("CORS_ORIGINS", "http://localhost:5173,http://localhost:3000").split(",")
|
||||
if o.strip()
|
||||
]
|
||||
|
||||
# ============================================================
|
||||
# Initialisation
|
||||
# ============================================================
|
||||
@@ -26,7 +36,7 @@ app = FastAPI(
|
||||
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins = ["http://localhost:5173", "http://localhost:3000"],
|
||||
allow_origins = CORS_ORIGINS,
|
||||
allow_methods = ["GET"],
|
||||
allow_headers = ["*"],
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user