Add and retrieve hit counters per subpath, no validation
authorJacob <jobs@jacobcasper.com>
Sun, 7 Sep 2025 17:29:46 +0000 (12:29 -0500)
committerJacob <jobs@jacobcasper.com>
Sun, 7 Sep 2025 17:29:46 +0000 (12:29 -0500)
main.py

diff --git a/main.py b/main.py
index 1928927a50ae460c5f3cd765da3651122748f92d..88664d036fe07e1819e82b8249455a00d7f9d65e 100644 (file)
--- 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/<path:subpath>", methods=["GET"])
+def api(subpath):
+    app.logger.debug("subpath %s", subpath)
+    hits = r.incr(f"hits:{subpath}")
+    return {"hits": hits}
 
 
 def main():