server content gets served

This commit is contained in:
Jarian Cottingham 2025-10-17 00:45:10 -05:00
parent e8673fb0f6
commit 8a630e7ba3

View File

@ -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)