🔍 Code Extractor

function check_debug_endpoint

Maturity: 44

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.

File:
/tf/active/vicechatdev/vice_ai/dev_tools.py
Lines:
59 - 82
Complexity:
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

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function debug_cache_info 73.4% similar

    Flask debug endpoint that provides comprehensive cache busting information including static file versions, modification times, and cache buster values.

    From: /tf/active/vicechatdev/vice_ai/app.py
  • function get_cache_buster 58.0% similar

    Returns a cache-busting string that varies based on the application mode: current timestamp in debug mode or a static version string in production mode.

    From: /tf/active/vicechatdev/vice_ai/complex_app.py
  • function main_v50 55.4% similar

    A command-line interface (CLI) entry point that parses command-line arguments and dispatches to various development tool functions for managing browser cache, static files, and debug endpoints.

    From: /tf/active/vicechatdev/vice_ai/dev_tools.py
  • function debug_session_results 54.9% similar

    Flask debug endpoint that retrieves and categorizes analysis session results, providing detailed file summaries and metadata for troubleshooting purposes.

    From: /tf/active/vicechatdev/full_smartstat/app.py
  • function check_filecloud_structure 52.3% similar

    Diagnostic function that checks the FileCloud server structure and verifies accessibility of various paths including root, SHARED, and configured base paths.

    From: /tf/active/vicechatdev/SPFCsync/check_filecloud_structure.py
← Back to Browse