function check_debug_endpoint
Queries a debug endpoint to retrieve and display cache information from a web server, including debug mode status, cache buster values, and static file versions.
/tf/active/vicechatdev/vice_ai/dev_tools.py
59 - 82
simple
Purpose
This function is designed for debugging and monitoring purposes in web applications. It connects to a server's debug endpoint (/debug/cache-info) to retrieve cache-related metadata, helping developers verify cache configurations, track static file versions, and troubleshoot caching issues during development or deployment.
Source Code
def check_debug_endpoint(base_url="http://localhost:5000"):
"""Check the debug cache info endpoint"""
try:
response = requests.get(f"{base_url}/debug/cache-info", timeout=5)
if response.status_code == 200:
data = response.json()
print("🔍 Server Cache Info:")
print(f" Debug Mode: {data.get('debug_mode')}")
print(f" Cache Buster: {data.get('cache_buster')}")
print(f" Startup Version: {data.get('startup_version')}")
static_files = data.get('static_files', {})
if static_files:
print(" Static Files:")
for file, info in static_files.items():
version = info.get('version', 'N/A')
print(f" 📄 {file}: v{version}")
else:
print(f"⚠️ Debug endpoint returned {response.status_code}")
if response.status_code == 404:
print(" (Debug mode might not be enabled)")
except requests.RequestException as e:
print(f"❌ Could not connect to server: {e}")
print()
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
base_url |
- | 'http://localhost:5000' | positional_or_keyword |
Parameter Details
base_url: The base URL of the server to query. Defaults to 'http://localhost:5000'. Should be a complete URL including protocol (http/https) and optionally port number. The function appends '/debug/cache-info' to this base URL to form the complete endpoint path.
Return Value
This function does not return any value (implicitly returns None). Instead, it prints formatted output directly to stdout, displaying cache information including debug mode status, cache buster value, startup version, and a list of static files with their versions. If the request fails or the endpoint is unavailable, it prints error messages with appropriate emoji indicators.
Dependencies
requests
Required Imports
import requests
Usage Example
import requests
# Check debug endpoint on default localhost:5000
check_debug_endpoint()
# Check debug endpoint on a custom server
check_debug_endpoint(base_url="http://example.com:8080")
# Check debug endpoint on production server
check_debug_endpoint(base_url="https://myapp.production.com")
# Example output:
# 🔍 Server Cache Info:
# Debug Mode: True
# Cache Buster: abc123
# Startup Version: 1.2.3
# Static Files:
# 📄 main.css: v456
# 📄 app.js: v789
Best Practices
- This function should only be used in development or staging environments, not in production, as debug endpoints typically expose sensitive internal information
- Ensure the debug endpoint is properly secured or disabled in production deployments
- The function uses a 5-second timeout to prevent hanging on unresponsive servers
- Handle the printed output appropriately if using this function in automated scripts or CI/CD pipelines
- The function gracefully handles connection errors and non-200 status codes, making it safe to call even when the server is down
- Consider capturing stdout if you need to programmatically process the output instead of just displaying it
- The function expects a specific JSON structure from the endpoint; ensure your server's debug endpoint matches this format
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function debug_cache_info 73.4% similar
-
function get_cache_buster 58.0% similar
-
function main_v50 55.4% similar
-
function debug_session_results 54.9% similar
-
function check_filecloud_structure 52.3% similar