@@ -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)}
|
||||
|
||||
مرجع در شماره جدید
مسدود کردن کاربر