feat: add middleware
This commit is contained in:
parent
720f8e6b7c
commit
aad6ab8c6f
30
Back/main.py
30
Back/main.py
|
|
@ -1,5 +1,5 @@
|
|||
from contextlib import asynccontextmanager
|
||||
from fastapi import FastAPI, Depends
|
||||
from fastapi import FastAPI, Depends, Request
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi_swagger import patch_fastapi
|
||||
|
||||
|
|
@ -35,7 +35,7 @@ async def lifespan(app: FastAPI):
|
|||
await close_livekit_api()
|
||||
await redis_client.close()
|
||||
|
||||
global_limiter = RateLimiter(requests=120, window_seconds=60, scope="global")
|
||||
global_limiter = RateLimiter(requests=30, window_seconds=60, scope="global")
|
||||
|
||||
app = FastAPI(
|
||||
title="NEDA API",
|
||||
|
|
@ -54,21 +54,21 @@ patch_fastapi(app,docs_url="/swagger")
|
|||
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=["*"],
|
||||
allow_origins=[
|
||||
"https://pathfinder.wikm.ir",
|
||||
"http://localhost:8000",
|
||||
],
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
allow_methods=["GET", "POST", "PUT", "DELETE", "*"], # محدود کردن متدها
|
||||
allow_headers=["Authorization", "Content-Type"], # محدود کردن هدرها
|
||||
)
|
||||
# app.add_middleware(
|
||||
# CORSMiddleware,
|
||||
# allow_origins=[
|
||||
# "https://app.neda.com",
|
||||
# "http://localhost:3000" # فقط برای تست برنامهنویس فرانتاند
|
||||
# ],
|
||||
# allow_credentials=True,
|
||||
# allow_methods=["GET", "POST", "PUT", "DELETE"], # محدود کردن متدها
|
||||
# allow_headers=["Authorization", "Content-Type"], # محدود کردن هدرها
|
||||
# )
|
||||
|
||||
@app.middleware("http")
|
||||
async def add_security_headers(request: Request, call_next):
|
||||
response = await call_next(request)
|
||||
response.headers["X-Content-Type-Options"] = "nosniff"
|
||||
response.headers["X-Frame-Options"] = "DENY"
|
||||
return response
|
||||
|
||||
# -------------------------
|
||||
# Routers
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user