controlpanel-old/backend/main.py

43 lines
954 B
Python

from fastapi import FastAPI, Depends, Response
from fastapi.staticfiles import StaticFiles
from pydantic import BaseSettings, BaseModel
from models import User
from auth import get_current_user, auth_router
class Settings(BaseSettings):
dev_mode: bool = False
settings = Settings()
app = FastAPI()
app.include_router(
auth_router,
prefix="/auth",
tags=["auth"]
)
@app.get("/test")
async def read_test(user = Depends(get_current_user)):
return {"name": user.username, "foo": "bar"}
if settings.dev_mode:
import httpx
@app.get("/{path:path}")
async def proxy(path: str, response: Response):
async with httpx.AsyncClient() as client:
proxy = await client.get(f"http://localhost:3000/{path}")
response.body = proxy.content
response.status_code = proxy.status_code
return response
else:
app.mount("/", StaticFiles(directory="frontend", html=True), name="frontend")