From 8a630e7ba370f145ca3df215e136a097305b7c1e Mon Sep 17 00:00:00 2001 From: Jarian Cottingham Date: Fri, 17 Oct 2025 00:45:10 -0500 Subject: [PATCH] server content gets served --- articleServer/app.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/articleServer/app.py b/articleServer/app.py index d716ad9..988b0f3 100644 --- a/articleServer/app.py +++ b/articleServer/app.py @@ -184,5 +184,49 @@ def health_check(): return jsonify({"status": "healthy"}) +@app.route("/article/content", methods=["GET"]) +def article_content_endpoint(): + """HTTP endpoint to get the full content of a specific article by file path.""" + try: + # Get the file path from query parameters + file_path = request.args.get("path") + + if not file_path: + return jsonify({"error": "Missing 'path' parameter"}), 400 + + # Validate that the file exists and is within our article directory + # We'll ensure the file path is safe by checking it's under ARTICLE_DIR + file_path = os.path.abspath(file_path) + article_dir = os.path.abspath(ARTICLE_DIR) + + if not file_path.startswith(article_dir): + return jsonify( + {"error": "Invalid file path - must be within article directory"} + ), 400 + + if not os.path.exists(file_path): + return jsonify({"error": "Article file not found"}), 404 + + # Read the content of the article file + with open(file_path, "r", encoding="utf-8") as f: + content = f.read() + + # Get basic info about the article + outlet = os.path.basename(os.path.dirname(file_path)) + filename = os.path.basename(file_path) + + response_data = { + "path": file_path, + "name": filename, + "outlet": outlet, + "content": content, + } + + return jsonify(response_data) + + except Exception as e: + return jsonify({"error": str(e)}), 500 + + if __name__ == "__main__": app.run(host="0.0.0.0", port=5008, debug=True)