integrate webserver into cli #161
7
pkgs/clan-cli/clan_cli/webui/app.py
Normal file
7
pkgs/clan-cli/clan_cli/webui/app.py
Normal file
@ -0,0 +1,7 @@
|
||||
from fastapi import FastAPI
|
||||
|
||||
from .routers import health, root
|
||||
|
||||
app = FastAPI()
|
||||
app.include_router(health.router)
|
||||
app.include_router(root.router)
|
0
pkgs/clan-cli/clan_cli/webui/routers/__init__.py
Normal file
0
pkgs/clan-cli/clan_cli/webui/routers/__init__.py
Normal file
8
pkgs/clan-cli/clan_cli/webui/routers/health.py
Normal file
8
pkgs/clan-cli/clan_cli/webui/routers/health.py
Normal file
@ -0,0 +1,8 @@
|
||||
from fastapi import APIRouter
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/health")
|
||||
async def health() -> str:
|
||||
return "OK"
|
9
pkgs/clan-cli/clan_cli/webui/routers/root.py
Normal file
9
pkgs/clan-cli/clan_cli/webui/routers/root.py
Normal file
@ -0,0 +1,9 @@
|
||||
from fastapi import APIRouter, Response
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/")
|
||||
async def root() -> Response:
|
||||
body = "<html><body><h1>Welcome</h1></body></html>"
|
||||
return Response(content=body, media_type="text/html")
|
@ -4,18 +4,9 @@ import urllib.request
|
||||
import webbrowser
|
||||
from threading import Thread
|
||||
|
||||
from fastapi import FastAPI
|
||||
|
||||
# XXX: can we dynamically load this using nix develop?
|
||||
from uvicorn import run
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
@app.get("/health")
|
||||
async def read_root() -> str:
|
||||
return "OK"
|
||||
|
||||
|
||||
def defer_open_browser(base_url: str) -> None:
|
||||
for i in range(5):
|
||||
@ -33,7 +24,7 @@ def start_server(args: argparse.Namespace) -> None:
|
||||
target=defer_open_browser, args=(f"http://[{args.host}]:{args.port}",)
|
||||
).start()
|
||||
run(
|
||||
"clan_cli.webui.server:app",
|
||||
"clan_cli.webui.app:app",
|
||||
host=args.host,
|
||||
port=args.port,
|
||||
log_level=args.log_level,
|
||||
|
@ -46,7 +46,7 @@ git stash push --quiet --keep-index --message "treefmt pre-commit"
|
||||
trap restore_stash EXIT
|
||||
|
||||
# Run treefmt on the files in the index and record the result.
|
||||
nix fmt -- --no-cache --quiet "${commit_files[@]}"
|
||||
nix fmt -- --no-cache "${commit_files[@]}"
|
||||
|
||||
# Check if there is a diff
|
||||
git diff --name-only --exit-code
|
||||
|
Loading…
Reference in New Issue
Block a user