diff --git a/app.py b/app.py index 09a0936..cbca70c 100644 --- a/app.py +++ b/app.py @@ -1,13 +1,14 @@ # app.py import os +from typing import Any -from sanic import Sanic +from sanic import HTTPResponse, Sanic import sanic.response from sanic_ext import Config from api import api -from config import openapi_title, openapi_version, openapi_description +from config import openapi_title, openapi_version, openapi_description, hostnames from limiter import configure_limiter from auth import configure_auth @@ -54,7 +55,7 @@ app.blueprint(api) # https://sanic.dev/en/guide/how-to/static-redirects.html -def get_static_function(value): +def get_static_function(value) -> Any: return lambda *_, **__: value @@ -62,13 +63,20 @@ for src, dest in REDIRECTS.items(): app.route(src)(get_static_function(sanic.response.redirect(dest))) +@app.on_request +async def domain_check(request) -> HTTPResponse: + print(request.host) + if request.host not in hostnames: + return sanic.response.redirect(f"https://api.revanced.app/{request.path}") + + @app.on_response -async def add_cache_control(request, response): +async def add_cache_control(_, response): response.headers["Cache-Control"] = "public, max-age=300" @app.on_response -async def add_csp(request, response): +async def add_csp(_, response): response.headers[ "Content-Security-Policy" ] = "default-src * 'unsafe-inline' 'unsafe-eval' data: blob:;" diff --git a/config.py b/config.py index ba48b2e..6ef3231 100644 --- a/config.py +++ b/config.py @@ -2,6 +2,12 @@ backend: str = "github" redis: dict[str, str | int] = {"host": "localhost", "port": 6379} +hostnames: list[str] = [ + "api.revanced.app", + "deimos.revanced.app", + "localhost:8000", + "127.0.0.1:8000", +] # GitHub Backend Configuration