diff --git a/devterm/server/app.py b/devterm/server/app.py new file mode 100644 index 0000000..c79105b --- /dev/null +++ b/devterm/server/app.py @@ -0,0 +1,41 @@ +import uvicorn +from fastapi import FastAPI +from fastapi.responses import HTMLResponse +from fastapi.staticfiles import StaticFiles +from fastapi.templating import Jinja2Templates +from pathlib import Path + +from devterm.server.routes import router +from devterm.config import get_settings + + +def create_app() -> FastAPI: + app = FastAPI(title="Devterm", description="Developer Utilities") + + base_path = Path(__file__).parent.parent + templates_path = base_path / "templates" + static_path = base_path / "static" + + templates = Jinja2Templates(directory=str(templates_path)) + + app.include_router(router) + + @app.get("/", response_class=HTMLResponse) + async def home(): + settings = get_settings() + return templates.TemplateResponse("base.html", { + "request": {}, + "host": settings.host, + "port": settings.port + }) + + if static_path.exists(): + app.mount("/static", StaticFiles(directory=str(static_path)), name="static") + + return app + + +def run_server(): + settings = get_settings() + app = create_app() + uvicorn.run(app, host=settings.host, port=settings.port, reload=True)