MCPcopy Create free account
hub / github.com/cifertech/DisplayKit / create_app

Function create_app

server/main.py:53–127  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

51
52
53def create_app() -> FastAPI:
54 static_root = _static_root()
55 prod = _is_production()
56 app_version = os.environ.get("DISPLAYKIT_APP_VERSION", "1.0.0").strip() or "1.0.0"
57
58 app = FastAPI(
59 title="DisplayKit",
60 version=app_version,
61 docs_url=None if prod else "/docs",
62 redoc_url=None if prod else "/redoc",
63 openapi_url=None if prod else "/openapi.json",
64 )
65
66 # Outermost on the stack is added last: gzip responses, then optional host filter.
67 app.add_middleware(GZipMiddleware, minimum_size=512)
68 trusted = _trusted_hosts()
69 if trusted is not None:
70 app.add_middleware(TrustedHostMiddleware, allowed_hosts=trusted)
71
72 @app.get("/api/health")
73 def api_health() -> dict[str, str]:
74 payload: dict[str, str] = {
75 "status": "ok",
76 "service": "displaykit",
77 "version": app_version,
78 }
79 if not prod:
80 payload["env"] = "development"
81 return payload
82
83 @app.post("/api/project/summary")
84 def api_project_summary(project: dict[str, Any] = Body(...)) -> dict[str, Any]:
85 screens = project.get("screens")
86 if not isinstance(screens, list):
87 return {
88 "ok": False,
89 "error": "expected_top_level_array",
90 "detail": "body.screens must be a JSON array",
91 }
92
93 per_screen: list[dict[str, Any]] = []
94 total_elements = 0
95 for s in screens:
96 if not isinstance(s, dict):
97 continue
98 elements = s.get("elements")
99 n = len(elements) if isinstance(elements, list) else 0
100 total_elements += n
101 per_screen.append(
102 {
103 "id": s.get("id"),
104 "name": s.get("name"),
105 "element_count": n,
106 }
107 )
108
109 return {
110 "ok": True,

Callers 1

main.pyFile · 0.85

Calls 5

_static_rootFunction · 0.85
_is_productionFunction · 0.85
_trusted_hostsFunction · 0.85
build_icons_routerFunction · 0.85
build_tft_gif_routerFunction · 0.85

Tested by

no test coverage detected