From 77576d2ad45797dfee4689c0e18af1eb3e585b90 Mon Sep 17 00:00:00 2001 From: giles Date: Tue, 24 Feb 2026 08:27:54 +0000 Subject: [PATCH] Add fragment blueprint + sync shared: micro-frontend infrastructure Co-Authored-By: Claude Opus 4.6 --- app.py | 3 +- bp/__init__.py | 1 + bp/fragments/__init__.py | 1 + .../__pycache__/routes.cpython-312.pyc | Bin 0 -> 1757 bytes bp/fragments/routes.py | 34 ++++++++++++++++++ shared | 2 +- 6 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 bp/fragments/__init__.py create mode 100644 bp/fragments/__pycache__/routes.cpython-312.pyc create mode 100644 bp/fragments/routes.py diff --git a/app.py b/app.py index dd43b39..fba7eca 100644 --- a/app.py +++ b/app.py @@ -8,7 +8,7 @@ from jinja2 import FileSystemLoader, ChoiceLoader from shared.infrastructure.factory import create_base_app from shared.services.registry import services -from bp import register_account_bp, register_auth_bp +from bp import register_account_bp, register_auth_bp, register_fragments async def account_context() -> dict: @@ -51,6 +51,7 @@ def create_app() -> "Quart": # --- blueprints --- app.register_blueprint(register_auth_bp()) app.register_blueprint(register_account_bp()) + app.register_blueprint(register_fragments()) return app diff --git a/bp/__init__.py b/bp/__init__.py index 2113b69..fe22f4e 100644 --- a/bp/__init__.py +++ b/bp/__init__.py @@ -1,2 +1,3 @@ from .account.routes import register as register_account_bp from .auth.routes import register as register_auth_bp +from .fragments import register_fragments diff --git a/bp/fragments/__init__.py b/bp/fragments/__init__.py new file mode 100644 index 0000000..a4af44b --- /dev/null +++ b/bp/fragments/__init__.py @@ -0,0 +1 @@ +from .routes import register as register_fragments diff --git a/bp/fragments/__pycache__/routes.cpython-312.pyc b/bp/fragments/__pycache__/routes.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..ec170c002d141d0340d70dc27f57f518f8279aee GIT binary patch literal 1757 zcmZ`(&u<$=6rR~1{uMh8HYA0RW@$www~Z}95fY73k~XEKG>4?Bgb!>s-bvzU?cL6d zA#oGM(1<3eQb7?(FGxA`f>K0}{0T^064g>+l|v*z(3`7(RC40Y+PkC$=J5RX&71e; zd*3(yA(4n7SUvhz#cdg(pT&p2q^5)S-U4SGnJAA;Y)Td`NqGqiU$*3ul2=MBx29GjTaY(7my&~`*W zrhQm6GzbM{wSrZI{@K_g0WgEzHltj&xgpN8jO<2-tO{``baf-6ggFo;ZkUp56~Z{A zC(n-#zH@naM|zW-G9OAt!urx9OYeW~+x8UX~}Z8Cr@5XQUOVtOu3n(HP1^M%-vH z%4+&Q<_joe6>8}YC6mS3rvQpls{)_}&LxCF89cbtOaL$lp&2ofXBH3n0srbO!J~dm zs0_x_sx^k@&^Pi&IHQcXsJIGH;dUVgd{tORrJ|A>o+gG#D0Ag0!l{@M6pSW0J3||+o<6Y^Khcm;$Em-V znC&O8ox;_QTz}BoQ+gp#5u^xc9tF3+`4TrtSdnKA=D?0v^T;1Cs0Y{Dc}sJkKp3(q z-&1@Qjv)!nV_!En;JIIi+%;)k{!~@bg7nYHdFk1cZ=zc%k0N!1#-Zz@@4-}~oXqmv zG%r~hi6$W8#^I%MczU|P1i>T(J)$y-n|KN^Flv-di%?e)1>C6K`expcG)=3~lvff6 z4``|${x?4d_Yc7db{@7c>~N z;)froy?;omdJcL+icGPpMHdI$$+-*zLF4E_q#YiURhIQSv3jism>ys5;0Z=*> z;&Rn%6@zjQxyNnuh4!*(gAy}aECbJgyiyQnvOejo`Dg_a+98bSW3!@AJ` literal 0 HcmV?d00001 diff --git a/bp/fragments/routes.py b/bp/fragments/routes.py new file mode 100644 index 0000000..5ae8373 --- /dev/null +++ b/bp/fragments/routes.py @@ -0,0 +1,34 @@ +"""Account app fragment endpoints. + +Exposes HTML fragments at ``/internal/fragments/`` for consumption +by other coop apps via the fragment client. +""" + +from __future__ import annotations + +from quart import Blueprint, Response, request + +from shared.infrastructure.fragments import FRAGMENT_HEADER + + +def register(): + bp = Blueprint("fragments", __name__, url_prefix="/internal/fragments") + + _handlers: dict[str, object] = {} + + @bp.before_request + async def _require_fragment_header(): + if not request.headers.get(FRAGMENT_HEADER): + return Response("", status=403) + + @bp.get("/") + async def get_fragment(fragment_type: str): + handler = _handlers.get(fragment_type) + if handler is None: + return Response("", status=200, content_type="text/html") + html = await handler() + return Response(html, status=200, content_type="text/html") + + bp._fragment_handlers = _handlers + + return bp diff --git a/shared b/shared index e7d1809..b882770 160000 --- a/shared +++ b/shared @@ -1 +1 @@ -Subproject commit e7d180912b0dfc1ed40d70b002cfebde9250026a +Subproject commit b882770828be7c62bbd047146e03b83511a2397d