Add core devterm module files
Some checks failed
CI / test (3.10) (push) Has been cancelled
CI / test (3.11) (push) Has been cancelled
CI / test (3.12) (push) Has been cancelled
CI / test (3.8) (push) Has been cancelled
CI / test (3.9) (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / typecheck (push) Has been cancelled
CI / build-package (push) Has been cancelled
Some checks failed
CI / test (3.10) (push) Has been cancelled
CI / test (3.11) (push) Has been cancelled
CI / test (3.12) (push) Has been cancelled
CI / test (3.8) (push) Has been cancelled
CI / test (3.9) (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / typecheck (push) Has been cancelled
CI / build-package (push) Has been cancelled
This commit is contained in:
41
devterm/server/app.py
Normal file
41
devterm/server/app.py
Normal file
@@ -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)
|
||||||
Reference in New Issue
Block a user