diff --git a/app/common.py b/app/common.py index 552d787..2a2c883 100644 --- a/app/common.py +++ b/app/common.py @@ -1,5 +1,6 @@ def parse_request(req) -> tuple: - port = req.headers.get("Port") - host = req.headers.get("Host") + # port = req.headers.get("Port") + host = req.headers.get("Full-Upstream") ip_address = host.split(":")[0] + port = host.split(":")[1] return ip_address, port diff --git a/app/cosmos/cosmos.py b/app/cosmos/cosmos.py index 4ac51f6..00c60e9 100644 --- a/app/cosmos/cosmos.py +++ b/app/cosmos/cosmos.py @@ -2,10 +2,10 @@ from datetime import datetime, timedelta, timezone -def cosmos_health(ip: str, port: str, acceptable_time_delta: int = 60) -> tuple: +def cosmos_health(host: str, acceptable_time_delta: int = 60) -> tuple: acceptable_time_delta = timedelta(seconds=acceptable_time_delta) - url = f"http://{ip}:{port}/status" + url = f"http://{host}/status" response = requests.post(url) if response.status_code != 200: diff --git a/app/evm/ethereum.py b/app/evm/ethereum.py index a3bf656..b9a0ca7 100644 --- a/app/evm/ethereum.py +++ b/app/evm/ethereum.py @@ -2,13 +2,13 @@ import requests -def ethereum_health(ip: str, port: str, acceptable_time_delta: int = 60): +def ethereum_health(host: str, acceptable_time_delta: int = 60): acceptable_time_delta = timedelta(seconds=acceptable_time_delta) # Get latest block data payload = {"jsonrpc": "2.0", "method": "eth_getBlockByNumber", "params": ["latest", False], "id": 1} headers = {"Content-Type": "application/json"} - url = f"http://{ip}:{port}" + url = f"http://{host}" response = requests.post(url, headers=headers, json=payload) if response.status_code != 200: diff --git a/app/routes.py b/app/routes.py index 25fc52e..2ed7633 100644 --- a/app/routes.py +++ b/app/routes.py @@ -1,18 +1,18 @@ # routes.py from flask import Blueprint, request -from app.common import parse_request from app.health_check_functions import switch api = Blueprint("api", __name__) + @api.route("/health", methods=["GET"]) def health_check(): - ip, port = parse_request(request) - rpc_type = port[-2:] + host = request.headers.get("Full-Upstream") + rpc_type = host[-2:] health_check_function = switch.get(rpc_type) if health_check_function: - message, status = health_check_function(ip, port) + message, status = health_check_function(host) else: message, status = "Unknown RPC type", 400 diff --git a/docker-compose.yaml b/docker-compose.yaml index 18d1f33..bf7e6f9 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -4,8 +4,6 @@ services: image: lavender5/rpc_health_checker:master container_name: health restart: unless-stopped - env_file: - - ".env" ports: - "53336:53336" network_mode: "host"