Skip to content
This repository has been archived by the owner on Sep 2, 2023. It is now read-only.

Commit

Permalink
Merge pull request #72 from revanced/dev
Browse files Browse the repository at this point in the history
Changes to CORS and interfaces
  • Loading branch information
alexandreteles committed Jan 30, 2023
2 parents 56ac203 + e01a447 commit 451cfbf
Show file tree
Hide file tree
Showing 4 changed files with 640 additions and 196 deletions.
22 changes: 20 additions & 2 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from slowapi.util import get_remote_address
from slowapi.middleware import SlowAPIMiddleware
from slowapi import Limiter, _rate_limit_exceeded_handler
from fastapi.middleware.cors import CORSMiddleware

from fastapi_cache import FastAPICache
from fastapi_cache.decorator import cache
Expand Down Expand Up @@ -48,6 +49,13 @@

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

app = FastAPI(title=config['docs']['title'],
Expand All @@ -59,6 +67,16 @@
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
limiter = Limiter(key_func=get_remote_address,
default_limits=[
Expand Down Expand Up @@ -167,8 +185,8 @@ async def invalid_token_exception_handler(request, exc) -> JSONResponse:
async def startup() -> None:
"""Startup event handler"""

clients = Clients()
await clients.setup_admin()
# clients = Clients()
# await clients.setup_admin()
FastAPICache.init(RedisBackend(RedisConnector.connect(config['cache']['database'])),
prefix="fastapi-cache")

Expand Down
6 changes: 1 addition & 5 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ description = """
2. Client side caching is advised to avoid unnecessary requests
3. Abuse of the API will result in IP blocks
### Supporters
- Hosted by [Spheron](https://spheron.network?utm_source=revanced&utm_medium=oss) on the [Akash Network](https://akash.network/)
"""
version = "1.2.0"

Expand Down Expand Up @@ -59,7 +55,7 @@ database = 5
access_token_expires = false

[app]
repositories = ["TeamVanced/VancedMicroG", "revanced/revanced-patcher", "revanced/revanced-patches", "revanced/revanced-integrations", "revanced/revanced-manager", "revanced/revanced-cli", "revanced/revanced-website", "revanced/revanced-releases-api"]
repositories = ["revanced/revanced-patcher", "revanced/revanced-patches", "revanced/revanced-integrations", "revanced/revanced-manager", "revanced/revanced-cli", "revanced/revanced-website", "revanced/revanced-releases-api"]

[socials]
website = "https://revanced.app"
Expand Down
Loading

0 comments on commit 451cfbf

Please sign in to comment.