diff --git a/app.py b/app.py index 20e54f4..bfbd1c2 100644 --- a/app.py +++ b/app.py @@ -14,6 +14,31 @@ app.config.update( pages = FlatPages(app) +import requests +from flask import Flask, Response, request + +app = Flask(__name__) + +# The local address where Umami is running +UMAMI_LOCAL_URL = "http://192.168.0.37:3007" + +@app.route('/stats/', methods=['GET', 'POST']) +def umami_proxy(path): + url = f"{UMAMI_LOCAL_URL}/{path}" + + # Forward the request to Umami (including headers and data) + if request.method == 'POST': + resp = requests.post(url, json=request.json, headers=request.headers) + else: + resp = requests.get(url, params=request.args, headers=request.headers) + + # Clean up headers to avoid encoding issues + excluded_headers = ['content-encoding', 'content-length', 'transfer-encoding', 'connection'] + headers = [(name, value) for (name, value) in resp.raw.headers.items() + if name.lower() not in excluded_headers] + + return Response(resp.content, resp.status_code, headers) + @app.route('/') def index(): # Sort posts by date metadata