38 lines
967 B
Python
38 lines
967 B
Python
from contextlib import asynccontextmanager
|
|
|
|
from fastapi import FastAPI, Request
|
|
from fastapi.responses import RedirectResponse
|
|
from fastapi.staticfiles import StaticFiles
|
|
from fastapi.templating import Jinja2Templates
|
|
|
|
from app.db import init_db
|
|
|
|
templates = Jinja2Templates(directory="app/templates")
|
|
|
|
|
|
def create_app() -> FastAPI:
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
init_db()
|
|
yield
|
|
|
|
app = FastAPI(title="Moving Helper", lifespan=lifespan)
|
|
app.mount("/static", StaticFiles(directory="app/static"), name="static")
|
|
|
|
@app.get("/", include_in_schema=False)
|
|
def root() -> RedirectResponse:
|
|
return RedirectResponse(url="/boxes", status_code=302)
|
|
|
|
@app.get("/boxes")
|
|
def boxes_page(request: Request):
|
|
return templates.TemplateResponse(
|
|
request=request,
|
|
name="boxes.html",
|
|
context={"page_title": "Boxes"},
|
|
)
|
|
|
|
return app
|
|
|
|
|
|
app = create_app()
|