mirror of
https://github.com/revanced/revanced-api.git
synced 2025-06-13 05:37:44 +02:00
feat: hostname filtering
This commit is contained in:

committed by
Alexandre Teles (afterSt0rm)

parent
5bdf661555
commit
5482d9c442
18
app.py
18
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:;"
|
||||
|
Reference in New Issue
Block a user