Files
rose-ash/sx/app.py
giles 293f7713d6
Some checks failed
Build and Deploy / build-and-deploy (push) Failing after 16s
Auto-mount defpages: eliminate Python route stubs across all 9 services
Defpages are now declared with absolute paths in .sx files and auto-mounted
directly on the Quart app, removing ~850 lines of blueprint mount_pages calls,
before_request hooks, and g.* wrapper boilerplate. A new page = one defpage
declaration, nothing else.

Infrastructure:
- async_eval awaits coroutine results from callable dispatch
- auto_mount_pages() mounts all registered defpages on the app
- g._defpage_ctx pattern passes helper data to layout context

Migrated: sx, account, orders, federation, cart, market, events, blog

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-03 19:03:15 +00:00

66 lines
1.8 KiB
Python

from __future__ import annotations
import path_setup # noqa: F401
import sxc.sx_components as sx_components # noqa: F401
from shared.infrastructure.factory import create_base_app
from bp import register_pages
from services import register_domain_services
async def sx_docs_context() -> dict:
"""SX docs app context processor — fetches cross-service fragments."""
from quart import request, g
from shared.infrastructure.context import base_context
from shared.infrastructure.cart_identity import current_cart_identity
from shared.infrastructure.fragments import fetch_fragments
ctx = await base_context()
ctx["menu_items"] = []
ident = current_cart_identity()
user = getattr(g, "user", None)
cart_params = {}
if ident.get("user_id"):
cart_params["user_id"] = ident["user_id"]
if ident.get("session_id"):
cart_params["session_id"] = ident["session_id"]
auth_params = {"email": user.email} if user else None
cart_mini, auth_menu, nav_tree = await fetch_fragments([
("cart", "cart-mini", cart_params or None),
("account", "auth-menu", auth_params),
("blog", "nav-tree", {"app_name": "sx", "path": request.path}),
], required=False)
ctx["cart_mini"] = cart_mini
ctx["auth_menu"] = auth_menu
ctx["nav_tree"] = nav_tree
return ctx
def create_app() -> "Quart":
app = create_base_app(
"sx",
context_fn=sx_docs_context,
domain_services_fn=register_domain_services,
)
import sxc.sx_components # noqa: F401
from sxc.pages import setup_sx_pages
setup_sx_pages()
bp = register_pages(url_prefix="/")
app.register_blueprint(bp)
from shared.sx.pages import auto_mount_pages
auto_mount_pages(app, "sx")
return app
app = create_app()