fixes
This commit is contained in:
@@ -1,7 +1,14 @@
|
||||
from flask import Flask
|
||||
from .config import Config
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config.from_object(Config)
|
||||
def proxy_app():
|
||||
app = Flask(__name__)
|
||||
app.config.from_object(Config)
|
||||
|
||||
# Подключаем маршруты
|
||||
from proxy import rss_proxy, healthcheck
|
||||
rss_proxy.init_proxy(app)
|
||||
healthcheck.init_healthcheck(app)
|
||||
return app
|
||||
|
||||
|
||||
from proxy import rss_proxy, healthcheck
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
from flask import Response
|
||||
from proxy import app
|
||||
|
||||
@app.route("/health")
|
||||
def healthcheck():
|
||||
"""Health check route to monitor service status"""
|
||||
try:
|
||||
return Response("OK", status=200)
|
||||
except Exception as e:
|
||||
return f"Error: {e}", 500
|
||||
|
||||
def init_healthcheck(app):
|
||||
@app.route("/health")
|
||||
def healthcheck():
|
||||
"""Health check route to monitor service status"""
|
||||
try:
|
||||
return Response("healthy", status=200)
|
||||
except Exception as e:
|
||||
return f"Error: {e}", 500
|
||||
|
||||
@@ -2,26 +2,29 @@ import urllib.parse
|
||||
from flask import request, Response
|
||||
import requests
|
||||
import os
|
||||
from proxy import app
|
||||
|
||||
PROXY_URL = os.getenv("PROXY_URL")
|
||||
|
||||
@app.route("/proxy")
|
||||
def proxy():
|
||||
"""Proxy RSS feed with forced re-encoding to UTF-8"""
|
||||
raw_query = request.query_string.decode()
|
||||
if raw_query.startswith("url="):
|
||||
url = urllib.parse.unquote(raw_query[4:])
|
||||
else:
|
||||
return "Missing URL", 400
|
||||
|
||||
try:
|
||||
proxies = {"http": PROXY_URL, "https": PROXY_URL} if PROXY_URL else None
|
||||
r = requests.get(url, timeout=10, proxies=proxies)
|
||||
def init_proxy(app):
|
||||
@app.route("/proxy")
|
||||
def proxy():
|
||||
"""Proxy RSS feed with forced re-encoding to UTF-8"""
|
||||
raw_query = request.query_string.decode()
|
||||
if raw_query.startswith("url="):
|
||||
url = urllib.parse.unquote(raw_query[4:])
|
||||
else:
|
||||
return "Missing URL", 400
|
||||
|
||||
r.encoding = "windows-1251" if "windows-1251" in r.headers.get("content-type", "").lower() else r.apparent_encoding
|
||||
response_text = r.text.replace('<?xml version="1.0" encoding="windows-1251"?>', '<?xml version="1.0" encoding="UTF-8"?>')
|
||||
try:
|
||||
proxies = {"http": PROXY_URL, "https": PROXY_URL} if PROXY_URL else None
|
||||
r = requests.get(url, timeout=10, proxies=proxies)
|
||||
|
||||
return Response(response_text, content_type="application/xml; charset=utf-8")
|
||||
except Exception as e:
|
||||
return f"Error: {e}", 500
|
||||
r.encoding = "windows-1251" if "windows-1251" in r.headers.get("content-type",
|
||||
"").lower() else r.apparent_encoding
|
||||
response_text = r.text.replace('<?xml version="1.0" encoding="windows-1251"?>',
|
||||
'<?xml version="1.0" encoding="UTF-8"?>')
|
||||
|
||||
return Response(response_text, content_type="application/xml; charset=utf-8")
|
||||
except Exception as e:
|
||||
return f"Error: {e}", 500
|
||||
|
||||
@@ -1,18 +1,20 @@
|
||||
import requests
|
||||
import sys
|
||||
|
||||
|
||||
def check_health(url="http://localhost:5050/health"):
|
||||
try:
|
||||
response = requests.get(url, timeout=10)
|
||||
if response.status_code == 200:
|
||||
print("Health check passed")
|
||||
sys.exit(0) # Успешная проверка
|
||||
sys.exit(0)
|
||||
else:
|
||||
print(f"Health check failed: {response.status_code}")
|
||||
sys.exit(1) # Ошибка
|
||||
sys.exit(1)
|
||||
except requests.exceptions.RequestException as e:
|
||||
print(f"Health check failed: {e}")
|
||||
sys.exit(1) # Ошибка
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
check_health()
|
||||
|
||||
Reference in New Issue
Block a user