| """ |
| LTM — FastAPI server for the Hugging Face Docker Space. |
| |
| A 3D-enabled 2D design app. This server is intentionally minimal: it serves the |
| static single-page app (index.html) and any sibling assets. No AI proxy — the app |
| runs fully in the browser (Fabric.js for 2D, Babylon.js for 3D). |
| |
| Kept as a dynamic FastAPI/Docker server (not a static Space) so future server-side |
| features (asset storage, share links, etc.) can be added without re-plumbing hosting. |
| """ |
|
|
| from __future__ import annotations |
|
|
| import os |
| import time |
|
|
| from fastapi import FastAPI, HTTPException |
| from fastapi.responses import FileResponse |
|
|
| app = FastAPI(title="LTM — 3D-enabled 2D design app", version="2.0.0") |
|
|
|
|
| @app.get("/healthz") |
| async def healthz() -> dict: |
| return {"ok": True, "time": int(time.time())} |
|
|
|
|
| @app.get("/") |
| async def root(): |
| return FileResponse("index.html") |
|
|
|
|
| @app.get("/index.html") |
| async def root_alt(): |
| return FileResponse("index.html") |
|
|
|
|
| @app.get("/{filename:path}") |
| async def static_files(filename: str): |
| """Serve any other repo-root file (favicon, etc.). Guards against path traversal.""" |
| if not filename or ".." in filename or filename.startswith("/"): |
| raise HTTPException(status_code=404) |
| if not os.path.isfile(filename): |
| raise HTTPException(status_code=404) |
| return FileResponse(filename) |
|
|