Fix issue where redirecting to endpoints page would only show table

This commit is contained in:
Peter Stockings
2024-11-09 19:20:06 +11:00
parent 120a94ff45
commit 0b7b804d62
2 changed files with 21 additions and 17 deletions

36
app.py
View File

@@ -535,18 +535,6 @@ def plot_query(query_id):
return plot_div return plot_div
def get_routes(): def get_routes():
return routes
@app.route('/endpoints')
def list_endpoints():
"""
Lists all API endpoints available in the Flask application.
This endpoint retrieves all registered routes, excluding static routes,
and displays their details such as endpoint name, URL, allowed HTTP methods,
view function name, and a brief description.
"""
routes = [] routes = []
for rule in app.url_map.iter_rules(): for rule in app.url_map.iter_rules():
if rule.endpoint == 'static': if rule.endpoint == 'static':
@@ -560,7 +548,26 @@ def list_endpoints():
'doc': app.view_functions[rule.endpoint].__doc__ 'doc': app.view_functions[rule.endpoint].__doc__
} }
routes.append(route_info) routes.append(route_info)
return routes
@app.route('/endpoints')
def list_endpoints():
"""
Lists all API endpoints available in the Flask application.
This endpoint retrieves all registered routes, excluding static routes,
and displays their details such as endpoint name, URL, allowed HTTP methods,
view function name, and a brief description.
"""
routes = get_routes()
if htmx:
return render_block(app.jinja_env, 'endpoints.html', 'content', routes=routes)
return render_template('endpoints.html', routes=routes)
@app.route('/endpoints/search')
def search_endpoints():
routes = get_routes()
search = request.args.get('search', '').lower() search = request.args.get('search', '').lower()
if search: if search:
routes = [ routes = [
@@ -572,10 +579,7 @@ def list_endpoints():
or (route['doc'] and search in route['doc'].lower()) or (route['doc'] and search in route['doc'].lower())
] ]
if htmx: return render_template('partials/endpoints_table.html', routes=routes)
return render_template('partials/endpoints_table.html', routes=routes)
return render_template('endpoints.html', routes=routes)
@app.teardown_appcontext @app.teardown_appcontext
def closeConnection(exception): def closeConnection(exception):

View File

@@ -11,7 +11,7 @@
<!-- Optional: Search or Filter functionality with HTMX --> <!-- Optional: Search or Filter functionality with HTMX -->
<div class="mb-4"> <div class="mb-4">
<input type="text" id="search" name="search" placeholder="Search endpoints..." <input type="text" id="search" name="search" placeholder="Search endpoints..."
class="w-full p-2 border border-gray-300 rounded" hx-get="/endpoints" class="w-full p-2 border border-gray-300 rounded" hx-get="{{ url_for('search_endpoints') }}"
hx-trigger="keyup changed delay:500ms, search" hx-push-url="true" hx-target="#endpoints-table" hx-trigger="keyup changed delay:500ms, search" hx-push-url="true" hx-target="#endpoints-table"
hx-include="[name='search']"> hx-include="[name='search']">
</div> </div>