From e61b10d732dc01a10774b766ef152544e81f2bf7 Mon Sep 17 00:00:00 2001 From: Jacob Date: Sun, 7 Sep 2025 12:29:46 -0500 Subject: [PATCH] Add and retrieve hit counters per subpath, no validation --- main.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index 1928927..88664d0 100644 --- a/main.py +++ b/main.py @@ -11,11 +11,11 @@ app = Flask(__name__) @app.route("/stats", methods=["GET"]) def stats(): try: - stats = r.get("stats") + stats = r.scan_iter() if stats is None: app.logger.debug("Uninitialized stats object") return {} - return r.get("stats") + return {"stats": [{stat: r.get(stat)} for stat in stats]} except redis.exceptions.ConnectionError as e: app.logger.exception(e) return Response("Internal Server Error", 500) @@ -24,9 +24,11 @@ def stats(): return {} -@app.route("/api/", methods=["GET"]) -def api(): - return {"req": request.values} +@app.route("/api/", methods=["GET"]) +def api(subpath): + app.logger.debug("subpath %s", subpath) + hits = r.incr(f"hits:{subpath}") + return {"hits": hits} def main(): -- 2.30.2