Merge pull request #1477 from adamoutler/redirect-to-docs

Redirect from / to /docs
This commit is contained in:
Jokob @NetAlertX
2026-02-01 09:16:56 +11:00
committed by GitHub
2 changed files with 29 additions and 1 deletions

View File

@@ -4,7 +4,7 @@ import os
# flake8: noqa: E402
from flask import Flask, request, jsonify, Response
from flask import Flask, redirect, request, jsonify, url_for, Response
from models.device_instance import DeviceInstance # noqa: E402
from flask_cors import CORS
from werkzeug.exceptions import HTTPException
@@ -1165,6 +1165,11 @@ def api_docs():
return send_from_directory(openapi_dir, 'swagger.html')
@app.route('/')
def index_redirect():
"""Redirect root to API documentation."""
return redirect(url_for('api_docs'))
# --------------------------
# DB query
# --------------------------

View File

@@ -0,0 +1,23 @@
# test/api_endpoints/test_docs.py - Tests for root redirect and API docs endpoints
from api_server import api_server_start
def test_index_redirect_logic():
"""Test the redirect function logic directly."""
with api_server_start.app.test_client() as client:
response = client.get("/", follow_redirects=False)
assert response.status_code == 302
assert response.location == '/docs'
def test_api_docs_logic():
"""Test that api_docs attempts to serve the correct file."""
with api_server_start.app.test_client() as client:
response = client.get("/docs")
assert response.status_code == 200
assert response.mimetype == "text/html"
response.direct_passthrough = False
data = response.get_data()
assert b"<!DOCTYPE html>" in data or b"<html>" in data