mirror of
https://github.com/revanced/revanced-releases-api.git
synced 2025-04-30 06:24:27 +02:00
feat(routing): add CORS middleware
This commit is contained in:
parent
e6af36c033
commit
b71c5425da
22
app/main.py
22
app/main.py
@ -11,6 +11,7 @@ from fastapi.responses import JSONResponse, UJSONResponse
|
|||||||
from slowapi.util import get_remote_address
|
from slowapi.util import get_remote_address
|
||||||
from slowapi.middleware import SlowAPIMiddleware
|
from slowapi.middleware import SlowAPIMiddleware
|
||||||
from slowapi import Limiter, _rate_limit_exceeded_handler
|
from slowapi import Limiter, _rate_limit_exceeded_handler
|
||||||
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
|
|
||||||
from fastapi_cache import FastAPICache
|
from fastapi_cache import FastAPICache
|
||||||
from fastapi_cache.decorator import cache
|
from fastapi_cache.decorator import cache
|
||||||
@ -48,6 +49,13 @@ from app.dependencies import load_config
|
|||||||
|
|
||||||
config: dict = load_config()
|
config: dict = load_config()
|
||||||
|
|
||||||
|
# Setup CORS config
|
||||||
|
|
||||||
|
allow_origins: list[str] = ['*']
|
||||||
|
allow_methods: list[str] = ['*']
|
||||||
|
allow_headers: list[str] = ['*']
|
||||||
|
allow_credentials: bool = True
|
||||||
|
|
||||||
# Create FastAPI instance
|
# Create FastAPI instance
|
||||||
|
|
||||||
app = FastAPI(title=config['docs']['title'],
|
app = FastAPI(title=config['docs']['title'],
|
||||||
@ -59,6 +67,16 @@ app = FastAPI(title=config['docs']['title'],
|
|||||||
default_response_class=UJSONResponse
|
default_response_class=UJSONResponse
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Hook up CORS middleware
|
||||||
|
|
||||||
|
app.add_middleware(
|
||||||
|
CORSMiddleware,
|
||||||
|
allow_origins=allow_origins,
|
||||||
|
allow_methods=allow_methods,
|
||||||
|
allow_headers=allow_headers,
|
||||||
|
allow_credentials=allow_credentials,
|
||||||
|
)
|
||||||
|
|
||||||
# Hook up rate limiter
|
# Hook up rate limiter
|
||||||
limiter = Limiter(key_func=get_remote_address,
|
limiter = Limiter(key_func=get_remote_address,
|
||||||
default_limits=[
|
default_limits=[
|
||||||
@ -167,8 +185,8 @@ async def invalid_token_exception_handler(request, exc) -> JSONResponse:
|
|||||||
async def startup() -> None:
|
async def startup() -> None:
|
||||||
"""Startup event handler"""
|
"""Startup event handler"""
|
||||||
|
|
||||||
clients = Clients()
|
# clients = Clients()
|
||||||
await clients.setup_admin()
|
# await clients.setup_admin()
|
||||||
FastAPICache.init(RedisBackend(RedisConnector.connect(config['cache']['database'])),
|
FastAPICache.init(RedisBackend(RedisConnector.connect(config['cache']['database'])),
|
||||||
prefix="fastapi-cache")
|
prefix="fastapi-cache")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user