diff --git a/app.py b/app.py index 4c8ca44..2eb82cc 100644 --- a/app.py +++ b/app.py @@ -4,23 +4,26 @@ import json app = FastAPI() -LIMIT = 10 +HISTORY_LIMIT = 10 +HISTORY_FILE = "storage/requests.json" -def store_last_request(last_request, filename='requests.json'): + +def store_last_request(last_request, filename=HISTORY_FILE): try: - with open(filename, 'r') as f: + with open(filename, "r") as f: data = json.load(f) except (FileNotFoundError, json.JSONDecodeError): data = [] data.append(last_request) - if len(data) > LIMIT: + if len(data) > HISTORY_LIMIT: data.pop(0) - with open(filename, 'w') as f: + with open(filename, "w") as f: json.dump(data, f) + @app.post("/", status_code=status.HTTP_200_OK) async def webhook_handler(request: Request, response: Response): @@ -35,25 +38,26 @@ async def webhook_handler(request: Request, response: Response): } store_last_request(last_request) - response.status_code = status.HTTP_200_OK return {"status": "ok"} + @app.get("/__last_request__", status_code=status.HTTP_200_OK) async def last_requests(): try: - with open('requests.json', 'r') as f: + with open(HISTORY_FILE, "r") as f: data = json.load(f) except (FileNotFoundError, json.JSONDecodeError): data = [] return data[-1:] + @app.get("/__history__", status_code=status.HTTP_200_OK) async def history(): try: - with open('requests.json', 'r') as f: + with open(HISTORY_FILE, "r") as f: data = json.load(f) except (FileNotFoundError, json.JSONDecodeError): data = [] diff --git a/compose.yml b/compose.yml new file mode 100644 index 0000000..be11c3d --- /dev/null +++ b/compose.yml @@ -0,0 +1,20 @@ +networks: + apps-proxy: + external: true + name: apps-proxy + +services: + catcher: + image: shadoll/scatcher + volumes: + - ./storage:/app/storage + networks: + - "apps-proxy" + labels: + traefik.enable: true + traefik.docker.network: apps-proxy + traefik.http.routers.catcher.entrypoints: websecure + traefik.http.routers.catcher.rule: Host(`catcher.rs.shadoll.dev`) + traefik.http.routers.catcher.tls: true + traefik.http.routers.catcher.tls.certresolver: letsencrypt + traefik.http.services.catcher.loadbalancer.server.port: 5000