Spaces:
Build error
Build error
File size: 1,131 Bytes
1c75c98 |
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 |
# tracklight_server/main.py
from fastapi import FastAPI, Depends
from fastapi.responses import RedirectResponse
from fastapi.security import OAuth2PasswordRequestForm
from .api import ingest, auth, dashboard, artifacts, sync
from contextlib import asynccontextmanager
from .db import duckdb
@asynccontextmanager
async def lifespan(app: FastAPI):
# Create the database and table on startup
duckdb.create_tables()
yield
app = FastAPI(title="Tracklight Server", lifespan=lifespan)
# Include the API routers
app.include_router(ingest.router, prefix="/api", tags=["ingest"])
app.include_router(artifacts.router, prefix="/api", tags=["artifacts"])
app.include_router(sync.router, prefix="/api", tags=["sync"])
app.include_router(dashboard.router, tags=["dashboard"])
@app.get("/")
def read_root():
return RedirectResponse(url="/dashboard")
# This is needed for the OAuth2PasswordBearer to work
@app.post("/token")
async def token(form_data: OAuth2PasswordRequestForm = Depends()):
# In a real app, you'd verify the username and password here
return {"access_token": auth.API_TOKEN, "token_type": "bearer"}
|