This commit is contained in:
Christoph K.
2026-03-11 16:26:11 +01:00
commit 402395c856
9 changed files with 236 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
FROM python:3.13-alpine
WORKDIR /app
COPY server.py .
CMD ["python", "server.py"]

View File

@@ -0,0 +1,15 @@
services:
dummyhttpserver:
image: python:3.13-alpine
container_name: dummyhttpserver
restart: unless-stopped
ports:
- "10001:8080"
volumes:
- ./server.py:/app/server.py:ro
- ./example.json:/data/example.json:ro
working_dir: /app
command: python server.py
environment:
- DATA_FILE=/data/example.json
- PORT=8080

View File

@@ -0,0 +1 @@
{"currentTemperatureC":22.5,"humidity":50}

27
dummyhttpserver/server.py Normal file
View File

@@ -0,0 +1,27 @@
from http.server import BaseHTTPRequestHandler, HTTPServer
import os
DATA_FILE = os.environ.get("DATA_FILE", "/data/example.json")
class Handler(BaseHTTPRequestHandler):
def do_GET(self):
try:
with open(DATA_FILE, "rb") as f:
body = f.read()
self.send_response(200)
self.send_header("Content-Type", "application/json")
self.send_header("Content-Length", str(len(body)))
self.end_headers()
self.wfile.write(body)
except FileNotFoundError:
self.send_error(404, "Data file not found")
def log_message(self, format, *args):
print(f"{self.address_string()} - {format % args}", flush=True)
if __name__ == "__main__":
port = int(os.environ.get("PORT", 8080))
print(f"Serving {DATA_FILE} on port {port}", flush=True)
HTTPServer(("", port), Handler).serve_forever()