اصلاح مشکل CORS
Verify / test (push) Failing after 17s

This commit is contained in:
2026-11-05 18:49:21 +03:30
والد 56c5ee23d3
کامیت 407b213222
3فایلهای تغییر یافته به همراه72 افزوده شده و 1 حذف شده
+9
مشاهده پرونده
@@ -10,6 +10,7 @@ from pathlib import Path
from typing import Annotated, Literal
from fastapi import FastAPI, File, Form, Header, HTTPException, Request, UploadFile
from fastapi.exceptions import RequestValidationError
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import FileResponse, JSONResponse, Response
from sqlalchemy import func, select, text
from sqlalchemy.exc import SQLAlchemyError
@@ -80,6 +81,14 @@ async def security(request, call_next):
})
return response
# Register after security so CORS also decorates its early authentication errors.
app.add_middleware(
CORSMiddleware,
allow_origins=['https://git.sadentel.net'],
allow_methods=['GET', 'POST', 'OPTIONS'],
allow_headers=['X-API-Key', 'X-Viewer-Token', 'Content-Type'],
)
@app.exception_handler(HTTPException)
async def http_error(request, exc):
detail = exc.detail if isinstance(exc.detail, dict) else {'code': 'http_error', 'message': str(exc.detail)}