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 contextlib import asynccontextmanager
|
||||||
from fastapi import FastAPI, Depends
|
from fastapi import FastAPI, Depends, Request
|
||||||
from fastapi.middleware.cors import CORSMiddleware
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
from fastapi_swagger import patch_fastapi
|
from fastapi_swagger import patch_fastapi
|
||||||
|
|
||||||
|
|
@ -35,7 +35,7 @@ async def lifespan(app: FastAPI):
|
||||||
await close_livekit_api()
|
await close_livekit_api()
|
||||||
await redis_client.close()
|
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(
|
app = FastAPI(
|
||||||
title="NEDA API",
|
title="NEDA API",
|
||||||
|
|
@ -54,21 +54,21 @@ patch_fastapi(app,docs_url="/swagger")
|
||||||
|
|
||||||
app.add_middleware(
|
app.add_middleware(
|
||||||
CORSMiddleware,
|
CORSMiddleware,
|
||||||
allow_origins=["*"],
|
allow_origins=[
|
||||||
|
"https://pathfinder.wikm.ir",
|
||||||
|
"http://localhost:8000",
|
||||||
|
],
|
||||||
allow_credentials=True,
|
allow_credentials=True,
|
||||||
allow_methods=["*"],
|
allow_methods=["GET", "POST", "PUT", "DELETE", "*"], # محدود کردن متدها
|
||||||
allow_headers=["*"],
|
allow_headers=["Authorization", "Content-Type"], # محدود کردن هدرها
|
||||||
)
|
)
|
||||||
# app.add_middleware(
|
|
||||||
# CORSMiddleware,
|
@app.middleware("http")
|
||||||
# allow_origins=[
|
async def add_security_headers(request: Request, call_next):
|
||||||
# "https://app.neda.com",
|
response = await call_next(request)
|
||||||
# "http://localhost:3000" # فقط برای تست برنامهنویس فرانتاند
|
response.headers["X-Content-Type-Options"] = "nosniff"
|
||||||
# ],
|
response.headers["X-Frame-Options"] = "DENY"
|
||||||
# allow_credentials=True,
|
return response
|
||||||
# allow_methods=["GET", "POST", "PUT", "DELETE"], # محدود کردن متدها
|
|
||||||
# allow_headers=["Authorization", "Content-Type"], # محدود کردن هدرها
|
|
||||||
# )
|
|
||||||
|
|
||||||
# -------------------------
|
# -------------------------
|
||||||
# Routers
|
# Routers
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user