mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
change(python): centralize router inclusion
Now, when we want to add, remove routes, our base routes should be defined in aurweb.routers.__init__.APP_ROUTES. Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
a1f46611e1
commit
3e048e9675
2 changed files with 27 additions and 14 deletions
|
@ -17,11 +17,12 @@ from starlette.middleware.sessions import SessionMiddleware
|
||||||
import aurweb.config
|
import aurweb.config
|
||||||
import aurweb.logging
|
import aurweb.logging
|
||||||
|
|
||||||
|
from aurweb import prometheus, util
|
||||||
from aurweb.auth import BasicAuthBackend
|
from aurweb.auth import BasicAuthBackend
|
||||||
from aurweb.db import get_engine, query
|
from aurweb.db import get_engine, query
|
||||||
from aurweb.models import AcceptedTerm, Term
|
from aurweb.models import AcceptedTerm, Term
|
||||||
from aurweb.prometheus import http_api_requests_total, http_requests_total, instrumentator
|
from aurweb.prometheus import instrumentator
|
||||||
from aurweb.routers import accounts, auth, html, packages, pkgbase, requests, rpc, rss, sso, trusted_user
|
from aurweb.routers import APP_ROUTES
|
||||||
from aurweb.templates import make_context, render_template
|
from aurweb.templates import make_context, render_template
|
||||||
|
|
||||||
# Setup the FastAPI app.
|
# Setup the FastAPI app.
|
||||||
|
@ -29,8 +30,8 @@ app = FastAPI()
|
||||||
|
|
||||||
# Instrument routes with the prometheus-fastapi-instrumentator
|
# Instrument routes with the prometheus-fastapi-instrumentator
|
||||||
# library with custom collectors and expose /metrics.
|
# library with custom collectors and expose /metrics.
|
||||||
instrumentator().add(http_api_requests_total())
|
instrumentator().add(prometheus.http_api_requests_total())
|
||||||
instrumentator().add(http_requests_total())
|
instrumentator().add(prometheus.http_requests_total())
|
||||||
instrumentator().instrument(app)
|
instrumentator().instrument(app)
|
||||||
|
|
||||||
|
|
||||||
|
@ -74,16 +75,9 @@ async def app_startup():
|
||||||
app.add_middleware(SessionMiddleware, secret_key=session_secret)
|
app.add_middleware(SessionMiddleware, secret_key=session_secret)
|
||||||
|
|
||||||
# Add application routes.
|
# Add application routes.
|
||||||
app.include_router(sso.router)
|
def add_router(module):
|
||||||
app.include_router(html.router)
|
app.include_router(module.router)
|
||||||
app.include_router(auth.router)
|
util.apply_all(APP_ROUTES, add_router)
|
||||||
app.include_router(accounts.router)
|
|
||||||
app.include_router(trusted_user.router)
|
|
||||||
app.include_router(rss.router)
|
|
||||||
app.include_router(packages.router)
|
|
||||||
app.include_router(pkgbase.router)
|
|
||||||
app.include_router(requests.router)
|
|
||||||
app.include_router(rpc.router)
|
|
||||||
|
|
||||||
# Initialize the database engine and ORM.
|
# Initialize the database engine and ORM.
|
||||||
get_engine()
|
get_engine()
|
||||||
|
|
|
@ -3,3 +3,22 @@ API routers for FastAPI.
|
||||||
|
|
||||||
See https://fastapi.tiangolo.com/tutorial/bigger-applications/
|
See https://fastapi.tiangolo.com/tutorial/bigger-applications/
|
||||||
"""
|
"""
|
||||||
|
from . import accounts, auth, html, packages, pkgbase, requests, rpc, rss, sso, trusted_user
|
||||||
|
|
||||||
|
"""
|
||||||
|
aurweb application routes. This constant can be any iterable
|
||||||
|
and each element must have a .router attribute which points
|
||||||
|
to a fastapi.APIRouter.
|
||||||
|
"""
|
||||||
|
APP_ROUTES = [
|
||||||
|
accounts,
|
||||||
|
auth,
|
||||||
|
html,
|
||||||
|
packages,
|
||||||
|
pkgbase,
|
||||||
|
requests,
|
||||||
|
trusted_user,
|
||||||
|
rss,
|
||||||
|
rpc,
|
||||||
|
sso,
|
||||||
|
]
|
||||||
|
|
Loading…
Add table
Reference in a new issue