diff --git a/config.json b/config.json index 84aaf3a..c7dba37 100644 --- a/config.json +++ b/config.json @@ -9,4 +9,4 @@ "route": "/api/logs", "log_file": "server.log" } -} \ No newline at end of file +} diff --git a/python-api/app.py b/python-api/app.py index bc7c4b5..41fa74c 100644 --- a/python-api/app.py +++ b/python-api/app.py @@ -5,8 +5,10 @@ app = Flask(__name__) # Chargement de la configuration partagée (config.json à la racine du projet) -config_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'config.json') -with open(config_path, 'r') as f: +config_path = os.path.join( + os.path.dirname(os.path.abspath(__file__)), "..", "config.json" +) +with open(config_path, "r") as f: config = json.load(f) # ------------------------------------------------------- @@ -36,10 +38,27 @@ def parse_logs(filepath): "warning_count": len(warnings), "info_count": len(infos), "errors": errors, - "warnings": warnings + "warnings": warnings, } +# Health check endpoint — returns the current status of the API service, +# including the project name, version, and port loaded from config.json +@app.route("/api/health", methods=["GET"]) +def health(): + return ( + jsonify( + { + "status": "ok", + "service": config["projet"], + "version": config.get("version", "1.0.0"), + "port": config["api"]["port"], + } + ), + 200, + ) + + @app.route("/api/logs", methods=["GET"]) def get_logs(): result = parse_logs(config["api"]["log_file"])