From 138200c3ba1383b2fb6d234a65d3452da5bf3bfd Mon Sep 17 00:00:00 2001 From: Mark Joachim Krallmann <169099857+jokro7cf@users.noreply.github.com> Date: Wed, 20 May 2026 09:36:35 +0200 Subject: [PATCH] Switch to hypercorn Hypercorn allows http2 --- README.md | 10 ++++------ env.example.yaml | 3 ++- hs-rest-api.service | 2 +- requirements.txt | 5 ++--- server.py | 4 ++-- 5 files changed, 11 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 1db042b..2119f72 100644 --- a/README.md +++ b/README.md @@ -73,15 +73,13 @@ Use the built-in FastAPI server for local testing: ```bash cd ~/hs.rest-api source venv/bin/activate -uvicorn main:app --reload --host 127.0.0.1 --port 8000 +hypercorn main:app --reload --bind 127.0.0.1:8000 ``` If you want the server accessible externally in a test environment via `xyz00.hostsharing.net`, set the host to `0.0.0.0`. Example: ```bash -uvicorn main:app --reload --host 0.0.0.0 --port 8000 +hypercorn main:app --reload --bind 0.0.0.0:8000 ``` -> **Warning:** Do not use the built-in server in production! - ### Container Podman/Docker @@ -90,13 +88,13 @@ podman run -d \ -p 8000:8000 \ -v /path/to/env.yaml:/app/env.yaml:ro \ --name hs-rest-api \ - docker pull ghcr.io/openadministration/hs.rest-api:v.xy + ghcr.io/openadministration/hs.rest-api:v.xy ``` Or docker-compose.yml: ```yaml services: hs-rest-api: - image: docker pull ghcr.io/openadministration/hs.rest-api:v.xy + image: ghcr.io/openadministration/hs.rest-api:v.xy ports: - "8000:8000" volumes: diff --git a/env.example.yaml b/env.example.yaml index 8b44caf..18bee8f 100644 --- a/env.example.yaml +++ b/env.example.yaml @@ -13,7 +13,8 @@ api: server: host: 127.0.0.1 port: 8000 - # Log level for both uvicorn access logs and application logs. + # Log level for both access logs and application logs. + # critical # error — XML-RPC faults and unexpected exceptions only # warning — + unknown API keys # info — + every XML-RPC call with PAC name (recommended for production) diff --git a/hs-rest-api.service b/hs-rest-api.service index c7c0321..3cf6f72 100644 --- a/hs-rest-api.service +++ b/hs-rest-api.service @@ -1,5 +1,5 @@ [Unit] -Description=hs.rest-api Uvicorn Service +Description=hs.rest-api Service After=network.target [Service] diff --git a/requirements.txt b/requirements.txt index e0932c7..65c775a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,8 +3,7 @@ pyyaml python-dotenv~=1.1.1 fastapi>=0.116.1,<0.117.0 pydantic~=2.11.7 -uvicorn[standard] +hypercorn python-multipart starlette~=0.47.3 -cachetools~=6.2.0 -gunicorn \ No newline at end of file +cachetools~=6.2.0 \ No newline at end of file diff --git a/server.py b/server.py index 2a58d8e..795a61b 100644 --- a/server.py +++ b/server.py @@ -1,4 +1,4 @@ -import uvicorn +import subprocess import yaml with open("env.yaml", "r") as file: @@ -8,4 +8,4 @@ log = env["log-level"] worker = env["worker"] if __name__ == "__main__": - uvicorn.run("main:app", host=host, port=port, log_level=log, workers=4) \ No newline at end of file + subprocess.run(["hypercorn", "main:app", "--bind", f"{host}:{port}", "--log-level", log, "--workers",str(worker)]) \ No newline at end of file