added proxy

This commit is contained in:
2026-06-23 14:23:59 +03:00
parent abfece614e
commit e241a91524
4 changed files with 43 additions and 6 deletions
Binary file not shown.
+5
View File
@@ -28,3 +28,8 @@ ELEVATION_PROBE_TTL_SEC = float(
ELEVATION_CONNECT_TIMEOUT = float(
os.environ.get("LORATESTER_ELEVATION_TIMEOUT", "8")
)
RF_API_URL = os.environ.get(
"LORATESTER_RF_API_URL",
"http://127.0.0.1:5603",
).rstrip("/")
RF_API_TIMEOUT = float(os.environ.get("LORATESTER_RF_API_TIMEOUT", "30"))
+35 -2
View File
@@ -3,11 +3,12 @@
import time
from pathlib import Path
from flask import Flask, jsonify, request, send_from_directory
import httpx
from flask import Flask, Response, jsonify, request, send_from_directory
from flask_cors import CORS
from core.auth import ANDROID_CLIENT_HEADER, is_android_client
from core.config import HOST, PORT
from core.config import HOST, PORT, RF_API_TIMEOUT, RF_API_URL
from core.models import ChatIn, TelemetryIn
from core import storage
from core.telemetry_body import telemetry_from_body
@@ -27,6 +28,38 @@ def index():
return resp
@app.route("/api/rf/<path:rf_path>", methods=["GET", "POST"])
def rf_api_proxy(rf_path: str):
target = f"{RF_API_URL}/{rf_path.lstrip('/')}"
if request.query_string:
target = f"{target}?{request.query_string.decode('utf-8', errors='ignore')}"
try:
with httpx.Client(timeout=RF_API_TIMEOUT) as client:
upstream = client.request(
request.method,
target,
content=request.get_data() if request.method != "GET" else None,
headers={
"Accept": request.headers.get("Accept", "application/json"),
"Content-Type": request.headers.get(
"Content-Type", "application/json"
),
},
)
except httpx.RequestError as e:
return jsonify({
"error": "RF API unavailable",
"detail": str(e),
"target": target,
}), 502
return Response(
upstream.content,
status=upstream.status_code,
content_type=upstream.headers.get("content-type", "application/json"),
)
@app.post("/api/telemetry")
def post_telemetry():
if not is_android_client(request.headers):
+3 -4
View File
@@ -2054,8 +2054,7 @@
}
function defaultApiDebugBase() {
const port = location.port === '5603' ? '' : ':5603';
return `${location.protocol}//${location.hostname}${port}`;
return '/api/rf';
}
function apiDebugNumber(id, fallback = null) {
@@ -2299,7 +2298,7 @@
} catch (e) {
apiDebugSetStatus(`Ошибка запроса: ${e.message || e}`, true);
apiDebugSetOutput(e.response ||
'Проверьте API base URL, доступность порта и CORS. Для API на том же сервере обычно подходит порт 5603.');
'Проверьте API base URL. По умолчанию используется same-origin proxy /api/rf.');
apiDebugSetSummary('Расчёт не выполнен.');
}
}
@@ -2407,7 +2406,7 @@
} catch (e) {
apiDebugSetStatus(`Ошибка расчёта линии: ${e.message || e}`, true);
apiDebugSetOutput(e.response ||
'Проверьте API base URL, доступность порта и CORS. Для API на том же сервере обычно подходит порт 5603.');
'Проверьте API base URL. По умолчанию используется same-origin proxy /api/rf.');
apiDebugSetSummary('Расчёт линии не выполнен.');
}
}