.
This commit is contained in:
15
base.py
15
base.py
@@ -22,8 +22,8 @@ app = FastAPI(
|
||||
contact={"name": "codey"},
|
||||
redirect_slashes=False,
|
||||
loop=loop,
|
||||
docs_url="/docs", # Swagger UI (default)
|
||||
redoc_url="/redoc", # ReDoc UI (default, but explicitly set)
|
||||
docs_url="/docs", # Swagger UI (default)
|
||||
redoc_url="/redoc", # ReDoc UI (default, but explicitly set)
|
||||
)
|
||||
|
||||
constants = importlib.import_module("constants").Constants()
|
||||
@@ -46,13 +46,12 @@ app.add_middleware(
|
||||
allow_headers=["*"],
|
||||
) # type: ignore
|
||||
|
||||
|
||||
# Add Scalar API documentation endpoint (before blacklist routes)
|
||||
@app.get("/scalar", include_in_schema=False)
|
||||
def scalar_docs():
|
||||
return get_scalar_api_reference(
|
||||
openapi_url="/openapi.json",
|
||||
title="codey.lol API"
|
||||
)
|
||||
return get_scalar_api_reference(openapi_url="/openapi.json", title="codey.lol API")
|
||||
|
||||
|
||||
"""
|
||||
Blacklisted routes
|
||||
@@ -73,7 +72,9 @@ def base_head():
|
||||
def disallow_get_any(request: Request, var: Any = None):
|
||||
path = request.path_params["path"]
|
||||
allowed_paths = ["widget", "misc/no", "docs", "redoc", "scalar", "openapi.json"]
|
||||
logging.info(f"Checking path: {path}, allowed: {path in allowed_paths or path.split('/', maxsplit=1)[0] in allowed_paths}")
|
||||
logging.info(
|
||||
f"Checking path: {path}, allowed: {path in allowed_paths or path.split('/', maxsplit=1)[0] in allowed_paths}"
|
||||
)
|
||||
if not (
|
||||
isinstance(path, str)
|
||||
and (path.split("/", maxsplit=1)[0] in allowed_paths or path in allowed_paths)
|
||||
|
Reference in New Issue
Block a user