File size: 1,335 Bytes
d1acd49
be189e0
d1acd49
be189e0
 
 
d1acd49
be189e0
 
d1acd49
 
 
 
 
 
 
be189e0
 
d1acd49
be189e0
d1acd49
 
 
 
be189e0
d1acd49
 
 
 
 
 
 
 
 
 
 
 
 
 
be189e0
d1acd49
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"""
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)