Files
developer_docs/test_portal.py
2026-05-20 16:11:13 +05:30

40 lines
1.7 KiB
Python

import urllib.request
import urllib.error
import time
URL = "https://developer.nearledaily.com/"
def test_portal():
print(f"Testing connectivity to {URL}...\n")
try:
start_time = time.time()
# Send a standard GET request with a user-agent
req = urllib.request.Request(URL, headers={'User-Agent': 'Mozilla/5.0'})
with urllib.request.urlopen(req) as response:
status_code = response.getcode()
html = response.read().decode('utf-8')
duration = round((time.time() - start_time) * 1000, 2)
if status_code == 200:
print(f"[SUCCESS] Server responded with HTTP 200 OK in {duration}ms!")
# Check for specific title tags or branding we added
if "NearleDaily API" in html or "nearledaily-docs" in html.lower() or "nearledaily" in html.lower():
print("[SUCCESS] Found NearleDaily branding in the page HTML. The app is serving the correct files!")
else:
print("[WARNING] Server responded with 200 OK, but couldn't find the expected React app HTML.")
else:
print(f"[ERROR] Server responded with unexpected status code: {status_code}")
except urllib.error.HTTPError as e:
print(f"[HTTP ERROR] The server responded, but returned an error status code: {e.code}")
except urllib.error.URLError as e:
print(f"[NETWORK ERROR] Failed to reach the server. Reason: {e.reason}")
print("Hint: If you just changed the DNS or Coolify port, wait a minute for it to apply/propagate.")
except Exception as e:
print(f"[UNEXPECTED ERROR] {str(e)}")
if __name__ == "__main__":
test_portal()