add umami endpoint
All checks were successful
Redeploy landing on Push / Explore-Gitea-Actions (push) Successful in 8s
All checks were successful
Redeploy landing on Push / Explore-Gitea-Actions (push) Successful in 8s
This commit is contained in:
25
app.py
25
app.py
@@ -14,6 +14,31 @@ app.config.update(
|
|||||||
|
|
||||||
pages = FlatPages(app)
|
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/<path:path>', 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('/')
|
@app.route('/')
|
||||||
def index():
|
def index():
|
||||||
# Sort posts by date metadata
|
# Sort posts by date metadata
|
||||||
|
|||||||
Reference in New Issue
Block a user