mirror of
https://github.com/ReVanced/revanced-api.git
synced 2026-01-11 22:06:19 +00: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
|
# app.py
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from sanic import Sanic
|
from sanic import HTTPResponse, Sanic
|
||||||
import sanic.response
|
import sanic.response
|
||||||
from sanic_ext import Config
|
from sanic_ext import Config
|
||||||
|
|
||||||
from api import api
|
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 limiter import configure_limiter
|
||||||
from auth import configure_auth
|
from auth import configure_auth
|
||||||
@@ -54,7 +55,7 @@ app.blueprint(api)
|
|||||||
# https://sanic.dev/en/guide/how-to/static-redirects.html
|
# https://sanic.dev/en/guide/how-to/static-redirects.html
|
||||||
|
|
||||||
|
|
||||||
def get_static_function(value):
|
def get_static_function(value) -> Any:
|
||||||
return lambda *_, **__: value
|
return lambda *_, **__: value
|
||||||
|
|
||||||
|
|
||||||
@@ -62,13 +63,20 @@ for src, dest in REDIRECTS.items():
|
|||||||
app.route(src)(get_static_function(sanic.response.redirect(dest)))
|
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
|
@app.on_response
|
||||||
async def add_cache_control(request, response):
|
async def add_cache_control(_, response):
|
||||||
response.headers["Cache-Control"] = "public, max-age=300"
|
response.headers["Cache-Control"] = "public, max-age=300"
|
||||||
|
|
||||||
|
|
||||||
@app.on_response
|
@app.on_response
|
||||||
async def add_csp(request, response):
|
async def add_csp(_, response):
|
||||||
response.headers[
|
response.headers[
|
||||||
"Content-Security-Policy"
|
"Content-Security-Policy"
|
||||||
] = "default-src * 'unsafe-inline' 'unsafe-eval' data: blob:;"
|
] = "default-src * 'unsafe-inline' 'unsafe-eval' data: blob:;"
|
||||||
|
|||||||
@@ -2,6 +2,12 @@
|
|||||||
|
|
||||||
backend: str = "github"
|
backend: str = "github"
|
||||||
redis: dict[str, str | int] = {"host": "localhost", "port": 6379}
|
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
|
# GitHub Backend Configuration
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user