Spaces:
Build error
Build error
# 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 | |
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"]) | |
def read_root(): | |
return RedirectResponse(url="/dashboard") | |
# This is needed for the OAuth2PasswordBearer to work | |
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"} | |